I need to plot MeanDailySteps (range 0 to 30000) and MeanDailySleepHours (0-600)on two different Y axis of the same chart with the column data ID (a unique string of discrete Characters which is common to both the Y axis variables) on the X axis. The data is in a dataframe "Steps_Sleep_Data".
I tried using the ggplot and scale_y_continuous as below, unfortunately this doesn't work. I tried other means using par(new = TRUE) which didn't work. I seem to be wrong somewhere.
Please help.
ggplot(data=Steps_Sleep_Data, aes(x=Id, y=MeanDailySteps, fill=Id,colour="red", label=MeanDailySteps))+
geom_bar(stat='identity')+
ggplot(data=Steps_Sleep_Data, aes(x=Id, y=MeanDailySleepMinutes, fill=Id, colour="blue", label=MeanDailySleepMinutes)) +
geom_bar(stat='identity')+
scale_y_continuous(sec.axis = ~.*500)+
theme(axis.text.y.left = element_text(color = "red"),
axis.text.y.right = element_text(color = "blue"))