如何在ggplot中绘制一个变量? [英] How to plot one variable in ggplot?
本文介绍了如何在ggplot中绘制一个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在搜索,但仍然找不到一个非常简单的问题的答案-我们如何在R中使用ggplot2生成一个变量的简单点图?
I'm searching but still can't find an answer to a quite simple question - how can we produce a simple dot plot of one variable with ggplot2 in R?
使用plot
命令非常简单:
plot(iris$Sepal.Length, type='p')
但是,当我尝试将一个变量传递给qplot并指定geom ="point"时,出现错误"UseMethod("scale_dimension")中的错误".
But when I'm trying to pass one variable to qplot and specifying geom="point", I'm getting an error "Error in UseMethod("scale_dimension")".
我们如何使用ggplot2绘制这样的图?
How can we make a plot like this but with ggplot2?
推荐答案
您可以使用seq_along
手动创建索引向量.
You can manually create an index vector with seq_along
.
library(ggplot2)
qplot(seq_along(iris$Sepal.Length), iris$Sepal.Length)
这篇关于如何在ggplot中绘制一个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文