Skip to content

Confidence band extending too far left #453

@corinne-riddell

Description

@corinne-riddell

One more for you... In the Nunavut panel (bottom right) - the data begins only at 2003 (unlike the other provinces that begin at 2002), but for some reason the confidence band extends to cover 2002 even though there is no data at 2002 in Nunavut.

problem

Here's the code for you. The ggplot is called plot1 and the plotly version is called gg2. Thanks!

library(ggplot2)
library(scales)
library(grid)
library(dplyr)
library(plotly)
dat <- read.csv("http://corinne-riddell.github.io/datasets/CS_graph.csv")
dat$ucl2 <- as.numeric(as.character(dat$ucl))
dat$lcl2 <- as.numeric(as.character(dat$lcl))

order <- dat %>% group_by(Label) %>% dplyr::summarise(Code=first(Code))

dat$CS2 <- dat$CS/100

dat$Lab2 <- factor(dat$Label, levels=c("Canada","Newfoundland and Labrador",
                                       "Prince Edward Island","Nova Scotia",
                                       "New Brunswick", "Quebec", "Ontario",
                                       "Manitoba", "Saskatchewan", "Alberta",
                                       "British Columbia", "Yukon Territory",
                                       "Northwest Territories", "Nunavut"
                                       ))

plot1 <- ggplot(dat, aes(x=Year, y=CS2)) + geom_ribbon(aes(ymin=lcl2/100, ymax=ucl2/100), col="#f0f0f0", alpha=0.5) +
  geom_point() + geom_line(lwd=0.5) + facet_wrap(~Lab2, ncol=4) +
  theme_minimal(base_size=15) + scale_y_continuous(labels=percent, name="Cesarean delivery rate (%)\n") +
  scale_x_continuous(name="\nYear") + theme(panel.border = element_rect(fill=NA))
plot1

gg2 <- ggplotly(plot1)
gg2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions