Problem
I have just started R two days back. I have gone through some basic R tutorials and I am able to plot two dimensional data. I pull data from an Oracle database. Now, I am having problems when I try to merge two graph types (Line and Bar) using secondary axis.
I have no problem, plotting this data on Excel. Following is the plot:
I am unable to plot it on R. I searched some related examples but I am unable to tweak it as per my requirements (Combining Bar and Line chart (double axis) in ggplot2)
Code
Following is the code I am using to plot bar and line graphs separately:
Bar:
p <- ggplot(data = df, aes(x = MONTHS, y = BASE)) +
geom_bar(stat="identity") +
theme_minimal() +
geom_text(aes(label = BASE), vjust = 1.6, color = "White", size = 2.5)
Line:
p1 <- ggplot(data = df, aes(x = MONTHS, y = df$INTERNETPERCENTAGE, group = 1)) +
geom_line() +
geom_point()
Data
Update: I have the following data (raw data cleansed of "," and "%" signs):
> dput(head(df,20))
structure(list(MONTHS = structure(c(11L, 10L, 3L, 5L, 4L, 8L,
1L, 9L, 7L, 6L, 2L, 13L, 12L), .Label = c("Apr-18", "Aug-18",
"Dec-17", "Feb-18", "Jan-18", "Jul-18", "Jun-18", "Mar-18", "May-18",
"Nov-17", "Oct-17", "Oct-18", "Sep-18"), class = "factor"), BASE = c(40756228L,
41088219L, 41642601L, 42017111L, 42439446L, 42847468L, 43375319L,
43440484L, 43464735L, 43326823L, 43190949L, 43015301L, 42780071L
), INTERNETUSERGREATERTHAN0KB = c(13380576L, 13224502L, 14044105L,
14239169L, 14011423L, 14736043L, 14487827L, 14460410L, 14632695L,
14896654L, 15019329L, 14141766L, 14209288L), INTERNETPERCENTAGE = c(33L,
32L, 34L, 34L, 33L, 34L, 33L, 33L, 34L, 34L, 35L, 33L, 33L),
SMARTPHONE = c(11610216L, 11875033L, 12225965L, 12412010L,
12760251L, 12781082L, 13142400L, 13295826L, 13422476L, 13408216L,
13504339L, 13413596L, 13586438L), SMARTPHONEPERCENTAGE = c(28L,
29L, 29L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 32L
), INTERNETUSAGEGREATERTHAN0KB4G = c(829095L, 969531L, 1181411L,
1339620L, 1474300L, 1733027L, 1871816L, 1967129L, 2117418L,
2288215L, 2453243L, 2624865L, 2817199L)), row.names = c(NA,
13L), class = "data.frame")