ggplot2顶部的y轴和x轴颠倒的图 [英] Plot with reversed y-axis and x-axis on top in ggplot2
本文介绍了ggplot2顶部的y轴和x轴颠倒的图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取ggplot2
绘图,该图的y轴和x轴颠倒了.我使用scale_y_reverse()
来使y轴反转,但无法弄清楚如何将x轴放置在顶部而不是底部.
I'm trying to get ggplot2
plot with reversed y-axis and x-axis on top. I used scale_y_reverse()
to get reversed y-axis but could not figured out how to put x-axis on the top rather than at bottom.
dfn <- read.table(header=T, text='
supp dose length
OJ 0.5 13.23
OJ 1.0 22.70
OJ 2.0 26.06
VC 0.5 7.98
VC 1.0 16.77
VC 2.0 26.14
')
library(ggplot2)
p1 <- ggplot(data=dfn, aes(x=dose, y=length, group=supp, colour=supp)) + geom_line() + geom_point()
p1 <- p1 + scale_y_reverse()
print(p1)
推荐答案
您需要ggvis来做到这一点:
You need ggvis to do that:
library(ggvis)
dfn %>% ggvis(~dose, ~length, fill= ~supp, stroke=~supp) %>% layer_lines(fillOpacity=0) %>%
scale_numeric('y', reverse=T) %>% add_axis('x',orient='top')
这篇关于ggplot2顶部的y轴和x轴颠倒的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文