小平面排序然后标记x轴

时间:2018-05-31 17:40:57

标签: r ggplot2

我有这个数据框,我想使用scale_x_discrete来标记x轴

varchar2(3)

任何想法如何修复它?

谢谢。

1 个答案:

答案 0 :(得分:0)

如果您希望x离散,则需要将其设为x = factor(row)的因素。
然后,只需在dat中明确引用scale_x_discrete数据框:

ggplot(dat, aes(x = factor(row), y = y)) + 
  geom_point() + 
  facet_wrap(~group) +
  scale_x_discrete(breaks = dat$row, labels = dat$LABEL) 

http://jnicol.github.io/particleground/

或者,您可以将x保持为连续状态,然后使用scale_x_continuous来重新标记刻度线:

ggplot(dat, aes(x = row, y = y)) + 
  geom_point() + 
  facet_wrap(~group) +
  scale_x_continuous(breaks = dat$row, labels = dat$LABEL)