如何在原始顺序ggplot2中设置x轴

时间:2017-09-10 20:47:56

标签: r ggplot2

我有一个数据框total_likes

total_likes <- data.frame(month = c("June","July","August"),
                          likes =c(24413,28839,35060))

我想在x轴上绘制月份,在y轴上绘制。到目前为止,我有这段代码:

ggplot(total_likes, aes(x = month, y = likes , group = 1)) +
  geom_point() +
  geom_line(size = 1.5, colour = "blue") 

这个输出是: enter image description here

轴问题有两个问题:

  1. 为什么x轴不在顺序&#34;六月,七月,八月和#34;?我该如何解决?

  2. 有没有办法让y轴从零开始而不是24000?

1 个答案:

答案 0 :(得分:1)

订购您的数据

total_likes <- data_frame(month = ordered(c("June","July","August"), month.name), 
                          likes =c(24413,28839,35060))