ggplots

Data Reshaping

library(reshape2)
prod_wage_melt <- prod_wage %>% 
  melt(id.vars = "Year", 
       measure.variables = c("Hourly_compensation", "Net_productivity"),
       variable.name = "Prod_or_Compensation", 
       value.name = "Cumulative_Changes")
prod_wage_2_melt <- prod_wage_2 %>%
  melt(id.vars = "Year", 
       measure.variables = c("Real_median_hourly_compensation", "Real_average_hourly_compensation", "Net_productivity"), 
       variable.name = "Prod_or_Compensation", 
       value.name = "Cumulative_Changes")
prod_wage_melt %>% str
## 'data.frame':    134 obs. of  3 variables:
##  $ Year                : int  1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 ...
##  $ Prod_or_Compensation: Factor w/ 2 levels "Hourly_compensation",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Cumulative_Changes  : num  0 6.3 10.5 11.8 15 20.8 23.5 28.7 33.9 37.1 ...
prod_wage_2_melt %>% str
## 'data.frame':    126 obs. of  3 variables:
##  $ Year                : int  1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 ...
##  $ Prod_or_Compensation: Factor w/ 3 levels "Real_median_hourly_compensation",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Cumulative_Changes  : num  0 -2 -0.5 0.4 1.3 2.5 1.9 1.1 -1.2 0.5 ...

Net Productivity and Hourly Compensation

library(ggplot2)
par(family = "HCR Dotum LVT")
main_title <- "Productivity and Compensation (1948-2014)"
x_lab <- "Year"
y_lab <- "Cumulative Changes since 1948 (%)"
var_lab <- c("Hourly Compensation", "Productivity")
legend_lab <-  c("1948-1973\nProductivity : 96.7%\nHourly Compensation : 91.3%", "1973-2014\nProductivity : 72.2%\nHourly Compensation : 9.2%")
end_df <- prod_wage_melt %>% subset(Year == 2014)
y1995_df <- prod_wage_melt %>% subset(Year == 1995)
text_lab <- end_df %>% 
  `[`(, "Cumulative_Changes") %>%
  format(digits = 1, nsmall = 1) %>%
  paste("%", sep ="")
(g1 <- ggplot() +
  geom_line(data = prod_wage_melt, 
            mapping = aes(x = Year, 
                          y = Cumulative_Changes, 
                          colour = Prod_or_Compensation), 
            size = 1.5, 
            show.legend = FALSE))

(g2 <- g1 + 
  geom_point(data = end_df, aes(x = Year, 
                                y = Cumulative_Changes, 
                                colour = Prod_or_Compensation), 
             size = 3, 
             show.legend = FALSE))

(g3 <- g2 +
  geom_text(data = y1995_df, aes(x = Year, 
                                 y = Cumulative_Changes - c(10, 20), 
                                 label = var_lab)) +
  geom_text(data = end_df, aes(x = Year, 
                               y = Cumulative_Changes + 10, 
                               label = text_lab)) +
  annotate("text", 
           x = c(1950, 1975), 
           y = 200, 
           label = legend_lab, 
           hjust = 0))

(g4 <- g3 +
  scale_colour_manual(values = c("blue", "cyan")) + 
  scale_x_continuous(breaks = c(1948, seq(1960, 2010, by = 10), 2014), 
                     labels = c(1948, seq(1960, 2010, by = 10), 2014)) +
  labs(title = main_title, x = x_lab, y = y_lab) + 
  theme_bw())

ggsave("../pics/Productivity_vs_Wages_ggplot.png", width = 8, height = 6)

Net Productivity vs Average and Median Hourly Compensation

par(family = "HCR Dotum LVT")
main_title_2 <- "Net Productivity, Average and Median Compensation (1973-2014)"
y_lab_2 <- "Cumulatove Changes since 1973 (%)"
var_lab_2 <- c("Real Median\n Hourly Compensation", "Real Average\n Hourly Compensation", "Net Productivity")
end_df_2 <- subset(prod_wage_2_melt, Year == 2014)
y2007.df <- subset(prod_wage_2_melt, Year == 2007)
(h1 <- ggplot() +
  geom_line(data = prod_wage_2_melt, aes(x = Year, 
                                         y = Cumulative_Changes, 
                                         colour = Prod_or_Compensation), 
            size = 1.5, 
            show.legend = FALSE))

(h2 <- h1 + 
  geom_point(data = end_df_2, aes(x = Year, 
                                  y = Cumulative_Changes, 
                                  colour = Prod_or_Compensation), 
             size = 3, 
             show.legend = FALSE))

(h3 <- h2 +
  geom_text(data = y2007.df, aes(x = Year, 
                                 y = Cumulative_Changes - c(5, 10, 10), 
                                 label = var_lab_2)) +
  geom_text(data = end_df_2, aes(x = Year + 2, 
                                 y = Cumulative_Changes, 
                                 label = paste(Cumulative_Changes, "%", sep = ""))))

blues_pal <- brewer.pal(9, "Blues")
(h4 <- h3 +
#   scale_color_manual(values = blues_pal[c(9, 6, 3)]) +
  scale_colour_manual(values = c("blue", "deepskyblue", "cyan")) + 
  scale_x_continuous(breaks = c(1973, seq(1980, 2010, by = 10), 2014), 
                     labels = c(1973, seq(1980, 2010, by = 10), 2014)) +
  labs(title = main_title_2, x = x_lab, y = y_lab_2) + 
  theme_bw())

ggsave("../pics/Productivity_vs_Wages_2_ggplot.png", width = 8, height = 6)