Skip to content

Instantly share code, notes, and snippets.

@icaroagostino
Created September 8, 2020 19:00
Show Gist options
  • Save icaroagostino/743fc4978620eab3c450b50d83abf178 to your computer and use it in GitHub Desktop.
Save icaroagostino/743fc4978620eab3c450b50d83abf178 to your computer and use it in GitHub Desktop.
# Exemplo de ggplot com facet e diferentes cores
library(ggplot2)
bike_filtered <- data.frame(
year = rep(c(2015, 2016, 2017), 40),
month = rep(c(1:12), 10),
average_hire = rep(rpois(12, 10), 10),
bikes_hired = rep(rpois(12, 10), 10)
)
bike_filtered$year <- as.factor(bike_filtered$year)
ggplot(data = bike_filtered, aes(x = month)) +
geom_line(aes(y = bikes_hired, group = 1), color = "grey") +
geom_line(aes(y = average_hire, color = year)) +
facet_wrap(~ year) + aes(fill = year) +
#adding shadded area between both lines
geom_ribbon(aes(ymin = bikes_hired, ymax = average_hire),
fill = "lightgrey", alpha = 0.5, group = 1)
# https://git.io/JUn5q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment