Skip to content

Instantly share code, notes, and snippets.

@rinze
Created April 18, 2020 16:11
Show Gist options
  • Save rinze/bb3dc11b393332af15c385536d0753fd to your computer and use it in GitHub Desktop.
Save rinze/bb3dc11b393332af15c385536d0753fd to your computer and use it in GitHub Desktop.
Plot code for https://rinzewind.org/blog-es/2020/donde-estamos.html Not pretty, but it does its job.
library(ggplot2)
theme_set(theme_bw(12))
data1 <- data.frame(location = c(rep(0, 10), 1:100, rep(100, 200), 100:1, rep(0, 10)),
style = 1)
#data1$style[(nrow(data1)-30):nrow(data1)] <- 2
data1$idx <- 1:nrow(data1)
plt1 <- ggplot(data1) + geom_line(aes(x = idx, y = location,
linetype = factor(style)),
show.legend = FALSE) +
xlab("Tiempo") + ylab("Cómo de mal está todo") +
theme_classic(20) +
scale_y_continuous(limits = c(0, 250)) +
theme(axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
geom_point(aes(x = 250, y = 100), size = 7) +
geom_text(aes(x = 250, y = 200, label = "Usted está aquí"), size = 12,
# hack to have smooth fonts
data = data.frame()) +
geom_segment(aes(x = 250, y = 180, xend = 250, yend = 120),
arrow = arrow())
plot(plt1)
ggsave('/tmp/2020_04_donde_estamos_01.jpg')
# Second plot
data2 <- data.frame(idx = 1:350)
data2$location <- log1p(data2$idx) ^ 2
data2$style <- 1
data2$style[(nrow(data2)-70):nrow(data2)] <- 2
plt2 <- ggplot(data2) + geom_line(aes(x = idx, y = location,
linetype = factor(style)),
show.legend = FALSE) +
xlab("Tiempo") + ylab("Cómo de mal está todo") +
theme_classic(20) +
scale_y_continuous(limits = c(0, 45)) +
theme(axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
geom_point(aes(x = 50, y = log1p(50)^2), size = 7) +
geom_text(aes(x = 50, y = 45, label = "Usted está aquí"), size = 12,
# hack to have smooth fonts
data = data.frame()) +
geom_segment(aes(x = 50, y = 40, xend = 50, yend = log1p(50)^2 + 3),
arrow = arrow())
plot(plt2)
ggsave('/tmp/2020_04_donde_estamos_02.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment