这可能听起来很简单,但我试图找到等效的代码plot(x,y, type="h")
作为qplot代码.我已经有了:
qplot(x,y,data,geom="point")
Run Code Online (Sandbox Code Playgroud)
Ben*_*ker 10
它有点笨重,但我认为你需要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()
Run Code Online (Sandbox Code Playgroud)
这给(y标签改编):

相反,使用直方图stat=identity:
qplot(data = d, x=x, y=y, stat="identity")
Run Code Online (Sandbox Code Playgroud)
得到:

为了完整性,plotwith type='h'看起来像这样:

使用 ggplot,您只需要一个带有观察向量的数据框,而不是每个值的计数。
ggplot(data, aes(x = x)) + geom_histogram()
Run Code Online (Sandbox Code Playgroud)