The final answer with code is as follows,
The code for the above diagram is as follows,
A) Data
structure(list(Year = 1994:2016, Kcalpd = c(86L, 91L, 98L, 107L,
116L, 126L, 123L, 112L, 103L, 102L, 103L, 92L, 77L, 59L, 43L,
29L, 19L, 14L, 13L, 12L, 12L, 10L, 9L), Tonnes = c(728364, 757467,
780423, 792756, 701685, 720710, 677292, 761649, 668218, 679042,
974355, 1005035, 1123090, 1055070, 1092498, 1100654, 899767,
1018462, 1046096, 1084173, 1158217, 802194, 276773)), row.names = c(NA,
-23L), class = "data.frame", .Names = c("Year", "Kcalpd", "Tonnes"
))
B) Code
scaleFactor <- max(wfd$Thtonnes) / max(wfd$Kcalpd)
ggplot(wfd, aes(x=Year, width=.4)) +
geom_col(aes(y=Thtonnes), fill="blue", position = position_nudge(x = -.4)) +
geom_col(aes(y=Kcalpd * scaleFactor), fill="red") +
scale_y_continuous(name="Thtonnes (Rice + Wheat)", sec.axis=sec_axis(~./scaleFactor, name="Kcal per day")) +
scale_x_continuous(breaks = seq(1994, 2016, 4)) +
theme(
axis.title.y.left=element_text(color="blue"),
axis.text.y.left=element_text(color="blue"),
axis.title.y.right=element_text(color="red"),
axis.text.y.right=element_text(color="red")
) +
labs(title = "Food Security in Venezuela, Cereals Production and Food Gap", x = element_blank())
There is no bid deal involved. Just increase the gap between the bars and shift one type by that margin to get them aligned side by side.