代码type =“h”在ggplot2中 [英] Code for type="h" in ggplot2
本文介绍了代码type =“h”在ggplot2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这听起来很简单,但我试图找到相当于 plot(x,y,type =h)
作为qplot代码。我已经有:
qplot(x,y,data,geom =point)
解决方案这有点笨重,但我认为你需要
geom_segment()
。d < - data.frame(x = 1:5,y = c (x = x,xend = x,y = 0,yend = y,data = d,geom =segment )
##或等价地
ggplot(d,aes(x = x,xend = x,y = 0,yend = y))+ geom_segment()
这给出(y标签适用):
相比之下,使用带有
stat = identity
的直方图:
qplot(data = d,x = x,y = y,stat =identity)
给出: .stack.imgur.com / pwN2n.pngalt =
为了完整性,
图
与type ='h'
看起来像t他的:
This may sound really simple but I'm trying to find the equivalent code to
plot(x,y, type="h")
as a qplot code. I already have:qplot(x,y,data,geom="point")
解决方案It's a little clunky, but I think you need
geom_segment()
.d <- data.frame(x=1:5,y=c(0.1,0.4,0.8,0.2,0.9)) library(ggplot2) qplot(x=x,xend=x,y=0,yend=y,data=d,geom="segment") ## or equivalently ggplot(d,aes(x=x,xend=x,y=0,yend=y))+geom_segment()
This gives (y label adapted):
In contrast, using the histogram with
stat=identity
:qplot(data = d, x=x, y=y, stat="identity")
gives:
For completeness, the
plot
withtype='h'
looks like this:这篇关于代码type =“h”在ggplot2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文