我成功地使用以下内容创建了一个图形:
# suppose I have a p <- ggplot(data=df, ...) then the following works
# I get those two segments plotted correctly
p <- p + geom_segment(aes(x=1,y=103,xend=1,yend=107))
p <- p + geom_segment(aes(x=5,y=103,xend=5,yend=107))
然而,如果我这样做:
values <- c(1, 5)
for (i in values) {
p <- p + geom_segment(aes(x=i,y=103,xend=i,yend=107))
}
它不起作用,只创建了最后一个片段。有人能指导一下这里出了什么问题吗?
geom_segment()
中使用aes()
。 - MrFlickprint
语句或使用force
不能解决问题吗? - csgillespiei
,而不是值。只有在实际绘制图形时,aes
才能强制解析名称。在这种情况下,force
有时很有用,但由于aes
的非标准评估,它在这种情况下无法帮助。 - MrFlick