【发布时间】:2017-10-26 15:54:49
【问题描述】:
我正在努力解决这个问题:
我有以下data.frame:
df<-data.frame(read.csv(file="C:/Users/136728/Desktop/R/TestIRIC.csv",
header=TRUE))
我尝试使用子集用 ggplot2 绘制下图:
ggplot(data = df) + geom_point(aes(x = x, y = y)) + geom_point(data = subset(subset(data = df, y > 0 & y < 100), x > 250 & x < 375), aes(x = x, y = y), colour = "pink")
这个想法是重现下图: enter image description here
但是我收到以下错误消息:“子集中错误(数据 = df,y > 0 & y
ggplot(data = df) + geom_point(aes(x = x, y = y)) + geom_point(data = subset(df, Group == "Group1"), aes(x = x, y = y), colour = "pink")
非常感谢您的帮助!
【问题讨论】:
-
它是
subset(x = df, y > 0 & y < 100)。subset不带data参数。 -
好的,然后我用下面的代码来做 y 突出显示:ggplot(data = df) + geom_point(aes(x = x, y = y)) + geom_point(data = subset( x = df, y > 0 & y 250 & x
-
尝试使用 data=df[df$y>0&df$y250&df$x
-
确实我觉得我应该指定x和y属于df,但是上面不起作用...
-
下次分享一个可重现的例子,比如
dput(head(df)),我们会看到你的数据并能够测试可能的解决方案。
标签: r object dataframe ggplot2 subset