# Homework 2

Q1 A. Using presidential and economics data frames from ggplot2 package, recreate the following graphs. Before you start making the plots, first understand the data sets well.

• Start with checking the help panel by typing ?presidential and ?economics in the console. This will describe the variables in your data sets.
• Take a peek at the data using head()
• Get summary of the variables

Note that you DON’T have to include all this in the homework. This is only for your own understanding of the data.

The font used below for labeling the bar graphs is “Impact”. You may not have the same font available on your computer. Use any alternative font. However, refrain from using the default fonts (i.e., sans, serif, and mono).

The plot is as follows. Below the plot I am giving you partial code to create this graph. You will have to choose correct arguments and their values. You have freedom to choose different colors, fonts, etc. but you should be able to produce a graph that tells the same story as this graph is telling. Remember that R help is your friend. Use ? in the console liberally to check each function’s syntax.

(7.5 points)

This is a skeleton code to recreate above graph. This will obviously not work out of the box. Note that you will have to decide on the values for arguements in almost all the cases. In some cases, you may have to include function arguements together with their values.

# Create a smaller data frame from presidential where start date is larger than
# the smallest date in economics

pres2 <- subset(presidential, start > economics\$date[1])

ggplot(data = economics) +
geom_rect(aes(xmin = , xmax = , fill = ),
data = pres2,
ymin = , ymax = , alpha =
) +
scale_fill_manual() +
geom_vline(aes(xintercept = ),
data = pres2,
colour = , alpha =
) +
geom_text(aes(
x = ,
y = , label = , family =
),
data = pres2,
vjust = 0.5,
angle =
) +
geom_line() +
labs() +
scale_x_date(breaks = , labels = scales::) +
theme(
panel.grid = ,
panel.background = ,
axis.line = ,
axis.text.x =
)

B. Using the same data frames as above, recreate the following graph. Take a note of differences in the two graphs.

NOTE: The font used here for labeling the bar graphs is “Open Sans”. You may not have the same font available on your computer. In that case, use any alternative font. However, refrain from using the default font OR the font you used in the previous graph.

(7.5 points)