I want to put distribution plots of different variables into a single image file. Every distribution plot (subplot) contain similar groups separated by colors.
Currently I'm using plotting each variable separately using ggplot. Then I use grid.arrange to combine all the subplots together I can represent all the distribtution.
(Example code below)
#plot1
plot_min_RTT <- ggplot(house_total_year, aes(x=min_RTT, colour = ISP)) +
geom_density(adjust = 1/2,alpha=0.1, size = 2)
#plot2
plot_MaxMSS <- ggplot(house_total_year, aes(x=MaxMSS, colour = ISP)) +
geom_density(adjust = 1/2,alpha=0.1, size = 2)
#plot3
plot_send_buffer_size <- ggplot(house_total_year, aes(x=send_buffer_size, colour = ISP)) +
geom_density(adjust = 1/2,alpha=0.1, size = 2)
#plot4
plot_maxSpeed <- ggplot(house_total_year_filtered, aes(x=download_speed_max_month, colour = ISP)) +
geom_density(adjust = 1/2,alpha=0.1, size = 2)
#combine
grid.arrange(plot_min_RTT,plot_MaxMSS,plot_send_buffer_size,plot_maxSpeed)
As can be seen, the variables used for x-axis of each subplot is different. But all has the similar grouped variables (ISP). I ended up with a single plot below:
However, what I actually want is to have only a single legend (ISP) for all subplots. I was thinking of using facet_wrap function from ggplot but I'm still struggling with that. Please help.
Any suggestion would be appreciated !
Thanks! :)