Here is the issue, I want to plot (I use tidyverse, GGPLOT packages) a second y-axis on the right of the plot but from what I've understood sec.axis only allows you to put a transformation of the first axis (eg: first axis * 19/4). That I don't want.
I want to express two variables that have various units of measure (scales) and I'd like to have the left y axis in the unit of the first variable and the right y axis in the unit of the second (with the appropriate scales). In essence, I'd like to use scale="free" but for both y axis.
Any idea? Thank's in advance.
Sorry, here's a very simple code to illustrate this.
library(tidyverse)
Year <- c(2010:2014)
OilPrice <- c(60:64)
GasPrice <- c(6789,6802,6580, 6890, 7020)
DATASET <- data.frame(Year, OilPrice, GasPrice) %>% as_tibble(DATASET) %>%
gather(key = "Prices", value = "value", -Year)
ggplot(DATASET, aes(Year, value, color=Prices)) + geom_point() + geom_line(aes(group=Prices)) +
labs(
title = "Prices evolution over time",
y="Prices") + theme(legend.position = "bottom")
As you can see the units are very disparate. I don't want to apply an arithmetic transformation rather I'd like to have Oil Prices on the Y-axis, ranging from 60 to 64 let's say and on the right Y-axis having the Gas Prices ranging from 6500 to 7200 eg. How can I do it?