我正在尝试使用facet_wrap或facet_grid生成绘图(目前没有偏好),但是在facet_wrap / facet_grid对象内的每个帧上显示数据点选择。
我读到您可以简单地从要包含在每个绘图中的数据集中删除faceting变量,但是无论出于什么原因,这似乎都不适合我。
这是在Rstudio版本1.1.453上。
我找到了以下代码示例:
ggplot(mpg, aes(displ, hwy)) +
geom_point(data = transform(mpg, class = NULL), colour = "grey85") +
geom_point() +
facet_wrap(~class)
几乎为下面的代码复制了它。上面的代码可以正常工作,但是由于我的实现中的任何原因,它都会返回一条错误消息。请注意,我也尝试过将两个geom功能都设置为geom_point。
ggplot(data = Total, aes(Total$Time, Total$Killing)) +
geom_jitter(data = transform(Total, Run = NULL), colour = "grey85") +
geom_point() +
facet_wrap(~Run)
错误:美学的长度必须为1或与数据相同(2700):x,y
这是我在尝试运行此代码时遇到的错误消息。
最终我的目标是运行以下代码,但出于上述问题的目的,我对其进行了一些简化。
ggplot(data = filter(Total, Cell_Line != "stDev"), aes(x= Time, y=Killing)) +
geom_line(data = filter(select(Total, -Run), Cell_Line == "Wild_Type"), aes(x = Time, y = filter(Total, Cell_Line == "Wild_Type")[,3])) +
geom_errorbar(aes(x = filter(Total, Cell_Line == "Wild_Type")[,2], ymax = filter(Total, Cell_Line == "Wild_Type")[,3] + filter(Total, Cell_Line == "stDev")[,3], ymin = filter(Total, Cell_Line == "Wild_Type")[,3] - filter(Total, Cell_Line == "stDev")[,3])) +
geom_point() +
facet_wrap(~Run)
这是dput(Total)的结果精简到前30行:
structure(list(Cell_Line = structure(c(5L, 12L, 13L, 1L, 2L,
3L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 15L, 14L, 5L, 12L, 13L, 1L,
2L, 3L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 15L, 14L), .Label = c("17",
"19", "20", "29", "3", "33", "38", "47", "49", "53", "55", "7",
"8", "stDev", "Wild_Type"), class = "factor"), Time = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("00",
"02", "04", "08", "12", "18", "24", "32", "40", "48", "56", "64",
"72", "80"), class = "factor"), Killing = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0704388, 0.2881066, -0.0132908,
0.04700991, 0.03049371, -0.02243472, 0.1513817, 0.129636, 0.09328508,
0.05876777, 0.1063291, 0.0357473, 0.1974026, 0.07732854, 0.07383331
)), row.names = c(NA, 30L), class = "data.frame")