【问题标题】:Sorting ggplot legends by factor (here: months)按因子对ggplot图例进行排序(这里:月)
【发布时间】:2014-10-08 13:33:25
【问题描述】:

如果你考虑这段代码:

library(ggplot2)
df <- as.data.frame(matrix(rnorm(8),4,2)) 
colnames(df) <- c("x","y") 
df$dates <- as.factor(c("april", "may", "june", "august"))

ggplot(df, aes(x=x, y=y, color=dates)) + geom_point(size=3, shape=20)

如何按月份的时间顺序对图例进行排序?

【问题讨论】:

标签: r ggplot2 r-factor


【解决方案1】:

df$dates&lt;- 行替换为:

m <- c("april", "may", "june", "august")
df$dates <- factor(m, levels = m)

【讨论】:

  • @nouse 可能也想要ordered=TRUE
猜你喜欢
  • 2011-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 2021-11-03
相关资源
最近更新 更多