我正在使用 R 从表格生成绘图。
我使用了命令a <- read.table("table.txt")
效果很好。当我输入“a”时,它会正确打印出我的完整表格。
我还输入了library(ggplot2)
所以我可以使用 ggplot。
这是我的第一个命令:
ggplot(a, aes(x=V2, y=V5, group=V7)) +
geom_point(size=4, aes(col=V7)) + xlab("Rank") +
ylab("Inter-helix angle (Degree)") +
opts(legend.position="none")
这个命令生成了所有的点,但是当我添加 xlim(0,110) + ylim(0,110)
时到最后,它给了我一个警告,并说“删除了包含缺失值的 101 行”(我的表有 101 行长)。生成的图完全是空的。发生了什么?
最佳答案
我猜测您的数据可能超出了您在 xlim
和 ylim
中指定的范围,例如:
library(ggplot2)
df <- data.frame(x=1:10,y=1:10)
ggplot(a, aes(x=x, y=y)) +
geom_point(size=4) + xlab("Rank") +
ylab("Inter-helix angle (Degree)")
工作正常,但是:
ggplot(df, aes(x=x, y=y)) +
geom_point(size=4) + xlab("Rank") +
ylab("Inter-helix angle (Degree)") + xlim(0,0.1) + ylim(0,0.1)
给出与您得到的相同的错误,因为没有值落在0
和0.1
Warning message: Removed 10 rows containing missing values (geom_point).
尽管没有您的数据,这只是最有可能的答案。顺便说一下,一般人倾向于使用coord_cartesian:
ggplot(df, aes(x=x, y=y)) +
geom_point(size=4) + xlab("Rank") +
ylab("Inter-helix angle (Degree)") + coord_cartesian(xlim=c(0,0.1)) +
coord_cartesian(ylim=c(0,0.1))
关于r - 当我设置 x 和 y 限制时,ggplot 会删除所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14486086/