library(tidyverse)
ggplot(mtcars, aes(cyl, mpg)) +
geom_point() +
theme_bw() +
geom_hline(aes(yintercept = 20), color = "red")
This code above is the nice black and white theme, with a red horizontal line. The code below also is supposed to be the black and white theme, this time with a red vertical line. But the plot lacks any color at all. Why is theme_bw()
stripping out all color from my plot below?
library(tidyverse)
library(lubridate)
df <-
tibble(
date = as.Date(41000:42000, origin = "1899-12-30"),
value = c(rnorm(500, 5), rnorm(501, 10))
) %>%
mutate(year = as.factor(year(date)))
ggplot(df, aes(date, value)) +
geom_line() +
geom_vline(
xintercept = as.numeric(df$date[yday(df$date) == 1]), color = "red"
) +
scale_x_date(
date_labels = "%b", breaks = scales::pretty_breaks(), expand = c(0, 0)
) +
facet_grid(.~ year, space = 'free_x', scales = 'free_x', switch = 'x') +
labs(x = "") +
theme_bw(base_size = 14, base_family = 'mono') +
theme(panel.grid.minor.x = element_blank()) +
theme(panel.spacing.x = unit(0, "line")) +
theme(strip.placement = 'outside', strip.background.x = element_blank())
geom_vline(size = 2, ...)
), all this happens because you split plot into facets and there edges cover the line (or remove facets). – pogibassize=2
red line, with asize=1
black line drawn on top of it. Looks like a racing stripe (which I don't want in this case) – stackinatortheme_classic()
and adds lines on top and right. – aosmith