'Change labels on facet plots
I currently have a plot with 6 facets labeled 1 to 6 in pandas, i wish to change these labels to road type if possible (Motorway, A Road, B Road etc)
the code i used for the plot
(ggplot(accidents, aes(x='weekday', y='Number_of_Casualties', colour = 'Urban_or_Rural_Area')) +
geom_jitter() +
facet_wrap('1st_Road_Class') +
ylim(0, 26) + #remove the outlyer of 52 casulties
ylab('Number of casualties') +
xlab('Day of the week') +
ggtitle('Figure 2: What affects the number of casualties in 2019') +
scale_color_discrete(labels = ['Urban accidents', 'Rural accidents', 'No data']) +
labs(color = 'Location area') +
theme(figure_size = (20, 8)))
accidents df
Number_of_Casualties Date Urban_or_Rural_Area 1st_Road_Class weekday
53 16-01-2019 1 1 thursday
50 17-01-2019 2 3 friday
35 17-01-2019 1 3 friday
58 18-01-2019 2 2 saturday
46 19-01-2019 2 4 sunday
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|