R: confidence interval is partially displayed using ggplot2 (using geom_smooth ())

I have the following simple R code:

disciplines <- c("A","C","B","D","E")
# To stop ggplot from imposing alphabetical ordering on x-axis
disciplines <- factor(disciplines, levels=disciplines, ordered=T)

d1 <- c(0.498, 0.521, 0.332, 0.04, 0.04)
d2 <- c(0.266, 0.202, 0.236, 0.06, 0.06)
d3 <- c(0.983, 0.755, 0.863, 0.803, 0.913)
d4 <- c(0.896, 0.802, 0.960, 0.611, 0.994)

df <- data.frame(disciplines, d1, d2, d3, d4)
df.m <- melt(df)
graph <- ggplot(df.m, aes(group=1,disciplines,value,colour=variable,shape=variable)) +
         geom_point() +
         geom_smooth(stat="smooth", method=loess, level=0.95) +
         scale_x_discrete(name="Disciplines") +
         scale_y_continuous(limits=c(-1,1), name="Measurement")

The result is as follows: enter image description here

Why is the confidence interval not displayed along the entire curve?

Notes:

  • I don't want to have fullrange=TRUEit because it just gives a single straight blue line instead of the zigzag shape in the current output.
  • I am comparing this plot with another plot that has negative values ​​in the range (0, -1), so the y axis has limits=c(-1,1))
+4
source share
2 answers

, , ( - [-1, 1], ). ggplot - - , . , oob=scales::rescale_none scale_y_continuous:

library(scales)
graph <- ggplot(df.m, aes(group=1,disciplines,value,colour=variable,shape=variable)) +
         geom_point() +
         geom_smooth(stat="smooth", method=loess, level=0.95) +
         scale_x_discrete(name="Disciplines") +
         scale_y_continuous(limits=c(-1,1), name="Measurement", oob=rescale_none)
+8

, , coord_cartesian:

ggplot(df.m, aes(group=1,disciplines,value,colour=variable,shape=variable)) +
         geom_point() +
         geom_smooth(stat="smooth", method=loess, level=0.95) +
         scale_x_discrete(name="Disciplines") +
         coord_cartesian(ylim = c(-1,1))
+4

All Articles