Task: Please make as many charts as you would like using ggplot2 I would like to see customisation, e.g. changing the name of the title or colours of the chart I have provided a google doc with various resources to help you here
Columns ID: A unique identifier for each respondent. AgeGroup: Age group of the respondent (“18-25”, “26-35”, “36-50”, “51+”). IncomeLevel: Income level of the respondent (“Low”, “Medium”, “High”). TransportMode: Preferred mode of transportation (“Car”, “Bike”, “Public Transport”, “Walking”, “Other”). Satisfaction: Satisfaction with the preferred mode of transportation on a scale of 1 to 10. Distance: Average daily distance traveled in kilometers. City: The city the respondent lives in (e.g., “City A”, “City B”, “City C”).
These are the examples I want to create for this challenge. There may be some additional tweaks, e.g. in Ex1 adding code to try to recreate the equivalent graph in Flourish.
Example 1: 1. Create a chart that shows how many people prefer each transport mode. 2. The chart should have transport modes on the x axis and the number of people on the y axis. 3. Add a meaningful title to the chart. 4. Label the x and y axes. 5. Change the legend title from “TransportMode” to Transport Modes.
ggplot(data, aes(x = TransportMode, fill = TransportMode)) +
geom_bar() +
theme_minimal() +
labs(title = "Preferred Mode of Transportation", x = "Transport Mode", y = "Count") +
scale_fill_discrete(name = "Transport Mode") +
# Added the below code to make it look like the flourish chart
theme(
plot.title = element_text(face = "bold", hjust = 0.5),
axis.title.x = element_text(face = "bold"),
axis.title.y = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
legend.text = element_text(size = 10),
legend.position = "top"
) +
guides(fill = guide_legend(nrow = 1))
Example 2: 1. Create the basic bar chart above, grouped by city (with the same colours for mode of transportation across cities). 2. Add a title to describe the chart. 3. Label the axes to explain what each axis represents. 4. Remove the legend. 5. Make the x axis labels easier to read, if necessary (e.g. rotate, space between x axis title and text, etc.).
ggplot(data, aes(x = TransportMode, fill = TransportMode)) +
geom_bar() +
theme_minimal() +
facet_wrap(~City) +
labs(title = "Transport Modes by City",
x = "Transport Mode",
y = "Count") +
theme(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),
axis.title.x = element_text(margin = margin(t = 10)))