显示从较大到较小的scaterplot R的值

时间:2017-01-18 14:47:48

标签: r ggplot2 scatter-plot

ggplot(mtcars) +
    geom_point(aes(x = wt, y = mpg, size = qsec), color = 'red') +
    geom_text(aes(wt, mpg, label=cyl)) + 
    geom_text_repel(aes(wt, mpg, label = rownames(mtcars))) +
    theme_classic(base_size = 16)

如果您运行此代码,您将得到如下图: enter image description here 我感兴趣的是改变qseq的顺序。意思是,biggest qsec将被分配smaller个圆圈,而最小的qsec将被分配更大的qsec。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

添加scale_size(trans = "reverse")解决了您的问题:

ggplot(mtcars) +
  geom_point(aes(x = wt, y = mpg, size = qsec), color = 'red') +
  geom_text(aes(wt, mpg, label=cyl)) + 
  geom_text_repel(aes(wt, mpg, label = rownames(mtcars))) +
  theme_classic(base_size = 16)+
  scale_size(trans = "reverse")

我只是添加数据图片以帮助其他人解决此问题 enter image description here