Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 缺少错误条结尾_R_Ggplot2 - Fatal编程技术网

R 缺少错误条结尾

R 缺少错误条结尾,r,ggplot2,R,Ggplot2,以下示例代码: require(ggplot2) stats <- data.frame(Day=0:5, Mean=c(3.2, 2.7, 0.8, 0.2, 0, 0), Q10=0.0, Q90=c(7.48, 4.0, 2.2, 1.2, 0, 0)) plot <- ggplot(stats, aes(x=Day, y=Mean)) + geom_point(size=4) + geom_line(size=1.5) + geom_errorbar(aes(

以下示例代码:

require(ggplot2)

stats <- data.frame(Day=0:5, Mean=c(3.2, 2.7, 0.8, 0.2, 0, 0), Q10=0.0, Q90=c(7.48, 4.0, 2.2, 1.2, 0, 0))

plot <- ggplot(stats, aes(x=Day, y=Mean)) +
  geom_point(size=4) +
  geom_line(size=1.5) +
  geom_errorbar(aes(ymin=Q10, ymax=Q90), width=0.2) +
  ggtitle("Example") +
  ylab("Pain Score") +
  scale_x_continuous("Day", expand=c(0.02,0), limits=c(0,15), breaks=0:15, labels=c("DOS", 1:15)) +
  scale_y_continuous("Pain Score", expand=c(0.02,0), limits=c(0,10), breaks=0:10)

print(plot)
require(ggplot2)

stats问题在于您的
scale\x\u continuous()
语句。从0开始设置
limits=
,但是第一个栏“T”超出此限制,因此它被删除(您可以看到警告,对于
geom_path()
一行被删除)。如果将
limits=
设置为例如从-0.3开始的星号,则会出现“T”

注意警告:

Warning message:
Removed 1 rows containing missing values (geom_path).
使用
coord_cartesian
在不丢弃数据的情况下指定限制:

plot <- ggplot(stats, aes(x=Day, y=Mean)) +
  geom_point(size=4) +
  geom_line(size=1.5) +
  geom_errorbar(aes(ymin=Q10, ymax=Q90), width=0.2) +
  ggtitle("Example") +
  ylab("Pain Score") +
  scale_x_continuous("Day", breaks=0:15, labels=c("DOS", 1:15)) +
  scale_y_continuous("Pain Score",  breaks=0:10) +
  coord_cartesian(xlim = c(-0.3, 15.3), ylim = c(-0.3,10.3))

print(plot)

plot虽然我最终使用了
coord_cartesian
解决方案,但它看起来也会起作用。
plot <- ggplot(stats, aes(x=Day, y=Mean)) +
  geom_point(size=4) +
  geom_line(size=1.5) +
  geom_errorbar(aes(ymin=Q10, ymax=Q90), width=0.2) +
  ggtitle("Example") +
  ylab("Pain Score") +
  scale_x_continuous("Day", breaks=0:15, labels=c("DOS", 1:15)) +
  scale_y_continuous("Pain Score",  breaks=0:10) +
  coord_cartesian(xlim = c(-0.3, 15.3), ylim = c(-0.3,10.3))

print(plot)