library(ggplot2)
library(dplyr)
library(distributional)
#ggplot
ggplot(economics, aes(date, unemploy)) + geom_line()
#ggdibbler
ggplot(uncertain_economics, aes(date, unemploy)) +
geom_line_sample(alpha=0.1)
# geom_step() is useful when you want to highlight exactly when
# the y value changes
recent <- economics[economics$date > as.Date("2013-01-01"), ]
uncertain_recent <- uncertain_economics[uncertain_economics$date > as.Date("2013-01-01"), ]
# geom line
ggplot(recent, aes(date, unemploy)) + geom_step()#ggplot
ggplot(uncertain_recent, aes(date, unemploy)) + geom_step_sample(alpha=0.5)#ggdibbler
# geom_path lets you explore how two variables are related over time,
# ggplot
m <- ggplot(economics, aes(unemploy, psavert))
m + geom_path(aes(colour = as.numeric(date)))
# ggdibbler
n <- ggplot(uncertain_economics, aes(unemploy, psavert))
n + geom_path_sample(aes(colour = as.numeric(date)), alpha=0.15)
# You can use NAs to break the line.
df <- data.frame(x = 1:5, y = c(1, 2, NA, 4, 5))
uncertain_df <- df |> mutate(y=dist_normal(y, 0.3))
# ggplot
ggplot(df, aes(x, y)) + geom_point() + geom_line()
# ggdibbler
ggplot(uncertain_df, aes(x, y)) +
geom_point_sample(seed=33) +
geom_line_sample(seed=33)
Run the code above in your browser using DataLab