This function dynamically creates either a scatter plot or a pie chart based on the user's choice in a Shiny application. The function adapts the plot type depending on the input provided: 'Scatter Plot' or 'Pie Chart'. The plots are designed to provide insights into the distribution of expenses across different categories, represented both in amounts and percentages.
Arguments
- expenses_data_summary
A data frame summarizing expenses data. It should contain at least the columns 'category', 'amount', and 'percentage', where 'percentage' represents the percentage share of each category in the total expenses.
- scatter_plot_type
A character string specifying the type of plot to generate. Expected values are "Scatter Plot" or "Pie Chart".
- colorblind_switch
A logical value indicating whether to use a colorblind-friendly color palette. The palette changes based on the value of this parameter.
Value
A Plotly object representing the specified type of plot (either a scatter plot or a pie chart). The function returns NULL if there is no data to plot.
Author
Group C composed of Marc Bourleau, Eleonore Gillain, Khrystyna Khmilovska, and Konstantinos Kourlimpinis.
Examples
# Create a sample data frame
expenses_summary <- data.frame(
category = c("Food", "Transport", "Utilities"),
amount = c(200, 150, 100),
percentage = c(40, 30, 30)
)
# Generate a scatter plot
scatter_plot <- generate_scatter_or_pie(expenses_summary, "Scatter Plot", FALSE)
print(scatter_plot)
# Generate a pie chart
pie_chart <- generate_scatter_or_pie(expenses_summary, "Pie Chart", FALSE)
print(pie_chart)