[英]plot a column of a data.frame in r using ggplot2
I have a data.frame 'test' that's similar to this: 我有一个data.frame'test'类似于以下内容:
names mean
a 1
b 2
c 3
d 4
I want to draw a boxplot only for the 'mean' column. 我只想为“平均值”列绘制一个箱线图。 How can I do this using ggplot2?
如何使用ggplot2执行此操作?
I tried this but it won't work: 我试过了,但是不起作用:
qplot(mean, data=test, geom="boxplot") + geom_jitter()
The geom_boxplot
requires variables for both axes. geom_boxplot
的两个轴都需要变量。 In your example you have only one variable and you have mapped it to the x variable, because that is the one named first in qplot
. 在您的示例中,您只有一个变量,并且已将其映射到x变量,因为这是
qplot
第一个命名的qplot
。 If you want to draw only one boxplot (all values belonging to the same group) you should create a variable in the test
data.frame that has the same value for each row. 如果只想绘制一个箱线图(所有值都属于同一组),则应在
test
data.frame中创建一个变量,每行的值都相同。 This would give you what you are after. 这会给你你所追求的。
test <- data.frame(
names = letters[1:4],
mean = 1:4,
x = "group")
qplot(x, mean, data = test, geom = "boxplot")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.