0

We run several experiments in a month and I would like to plot them using ggplot. Each have a different experiment id and I can easily plot them using the experiment id. However, I would like to display the month as the labels on x-axis instead of the experiment id. Is there and easy way to do that?

df<- data.frame(id = LETTERS[1:20], 
                value = runif(20,10,20),
                month = rep(month.name[1:5], each = 4))

)

ggplot(df, aes(id,value))+
geom_point()

Here is what I am looking to achieve

  • E.g. `ggplot(df, aes(id,value))+ geom_point() + scale_x_discrete(labels = df$month) ` – Axeman Sep 12 '19 at 19:43
  • Thanks this works but now it shows the same month on x-axis multiple times. Once for each separate experiment that month. Can I have it show the month name just once? – shashwat vajpeyi Sep 13 '19 at 15:40
  • So `ggplot(df, aes(month,value))+ geom_point()`? Not sure what you are getting at. – Axeman Sep 13 '19 at 16:05
  • So if I do that, I will get all points stacked up. I just added an image of the output I am looking for – shashwat vajpeyi Sep 13 '19 at 17:24
  • Have you looked at your example data? It really does not suggest an order like this, since January has id's A, E, I, M, Q. Not A, B, C, D, E, F. – Axeman Sep 13 '19 at 17:44
  • I don't think it matters because the experiment ids can be sorted and factored by month. Regardless, I changed the code in the question so it does generate the data you suggested. I am still not sure how to get the month name on x-axis just once – shashwat vajpeyi Sep 13 '19 at 19:30
  • 1
    If you just want points; `ggplot(df, aes(forcats::fct_inorder(month), value, group = id))+ geom_point(position = position_dodge(width = 1))` – Axeman Sep 13 '19 at 19:44

0 Answers0