library(ggplot2)
head(economics)
## # A tibble: 6 × 6
## date pce pop psavert uempmed unemploy
## <date> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1967-07-01 507. 198712 12.6 4.5 2944
## 2 1967-08-01 510. 198911 12.6 4.7 2945
## 3 1967-09-01 516. 199113 11.9 4.6 2958
## 4 1967-10-01 512. 199311 12.9 4.9 3143
## 5 1967-11-01 517. 199498 12.8 4.7 3066
## 6 1967-12-01 525. 199657 11.8 4.8 3018
# Using economics, plot unemploy vs. date
ggplot(economics, aes( x= date, y = unemploy)) +
# Make it a line plot
geom_line()

ggplot(economics, aes(x = date, y = unemploy ))+
geom_line()+
theme(
# For all rectangles, set the fill color to grey92
plot.background = element_rect(fill = 'grey92'),
# For the legend key, turn off the outline
legend.key = element_rect(color = NULL)
)

ggplot(economics, aes( x= date, y = unemploy)) +
# Make it a line plot
geom_line()+
theme(
# For all rectangles, set the fill color to grey92
plot.background = element_rect(fill = 'grey92'),
# For the legend key, turn off the outline
legend.key = element_rect(color = NULL)
)

plot_1 <- ggplot(economics, aes( x= date, y = unemploy)) +
# Make it a line plot
geom_line()+
theme(
rect = element_rect(fill = "grey92"),
legend.key = element_rect(color = NA),
axis.ticks = element_blank(),
panel.grid = element_blank(),
panel.grid.major.y = element_line(
color = "white",
size = 0.5,
linetype = "dotted"
),
# Set the axis text color to grey25
axis.text = element_text(color = "grey25"),
# Set the plot title font face to italic and font size to 16
plot.title = element_text(size = 16,
face = 'italic')
)
ggplot(economics, aes( x= date, y = unemploy)) +
# Make it a line plot
geom_line()+
theme(
rect = element_rect(fill = "grey92"),
legend.key = element_rect(color = NA),
axis.ticks = element_blank(),
panel.grid = element_blank(),
panel.grid.major.y = element_line(
color = "white",
size = 0.5,
linetype = "dotted"
),
# Set the axis text color to grey25
axis.text = element_text(color = "grey25"),
# Set the plot title font face to italic and font size to 16
plot.title = element_text(size = 16,
face = 'italic')
) +
theme(
# Set the plot margin in millimeters
plot.margin = margin(10,5,10,10, unit = 'mm')
)

library(ggthemes)
# Save the theme as theme_recession
theme_recession <- theme(
rect = element_rect(fill = "grey92"),
legend.key = element_rect(color = NA),
axis.ticks = element_blank(),
panel.grid = element_blank(),
panel.grid.major.y = element_line(color = "white", size = 0.5, linetype = "dotted"),
axis.text = element_text(color = "grey25"),
plot.title = element_text(face = "italic", size = 16),
legend.position = c(0.6, 0.1)
)
# Combine the Tufte theme with theme_recession
theme_tufte_recession <- theme_recession + theme_tufte()
# Add the Tufte recession theme to the plot
ggplot(economics, aes( x= date, y = unemploy)) +
# Make it a line plot
geom_line()+
theme(
rect = element_rect(fill = "grey92"),
legend.key = element_rect(color = NA),
axis.ticks = element_blank(),
panel.grid = element_blank(),
panel.grid.major.y = element_line(
color = "white",
size = 0.5,
linetype = "dotted"
),
# Set the axis text color to grey25
axis.text = element_text(color = "grey25"),
# Set the plot title font face to italic and font size to 16
plot.title = element_text(size = 16,
face = 'italic')
) + theme_tufte_recession

library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
theme_recession <- theme(
rect = element_rect(fill = "grey92"),
legend.key = element_rect(color = NA),
axis.ticks = element_blank(),
panel.grid = element_blank(),
panel.grid.major.y = element_line(color = "white", size = 0.5, linetype = "dotted"),
axis.text = element_text(color = "grey25"),
plot.title = element_text(face = "italic", size = 16),
legend.position = c(0.6, 0.1)
)
theme_tufte_recession <- theme_recession + theme_tufte()
theme_set(theme_tufte_recession)
# Draw the plot (without explicitly adding a theme)
p <- ggplot(economics, aes( x= date, y = unemploy)) +
# Make it a line plot
geom_line()
ggplotly(p)