3

I have three variables (Precipitation, Temperature and PAR Radiation) with different scales. I'm trying to plot these three variables together and I put the daily sum of precipitation represented by a barplot on the left side y axis and the daily average of temperature on the right side y axis. I'd like to put another y axis on the right side, with another scale, in order to represent the daily average of PAR radiation, but I can't. I'm using the ggplot package, because it is useful for other reasons.

I'm trying to reach something similar as in the pic:

I'm trying to reach something similar as in the pic

s__
  • 9,270
  • 3
  • 27
  • 45
Antonio Manco
  • 217
  • 2
  • 14
  • 1
    You can't have two unrelated y-axes in ggplot. The idea is documented at the documentation of `sec_axis`: `All secondary axes must be based on a one-to-one transformation of the primary axes.` – yarnabrina Jun 19 '19 at 17:06

2 Answers2

0

A discussion of this topic can be found here:

ggplot with 2 y axes on each side and different scales

A workaround solution can be found here:

https://rpubs.com/MarkusLoew/226759

Jonni
  • 804
  • 5
  • 16
  • 1
    Note that the question is how to create three different y-scales in the same plot, two of them on the same side. This question is a bit more complex than the answers you are suggesting. Nevertheless, the links you posted are a good start into the topic. – TimTeaFan Jun 20 '19 at 07:24
  • Exactly! This question is little bit harder. I've seen that this is possible with the standard R package for plotting, but I can't find a way with ggplot! – Antonio Manco Jun 21 '19 at 08:21
0

You can work with the Sandard R package http://evolvingspaces.blogspot.com/2011/05/multiple-y-axis-in-r-plot.html

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 08 '21 at 14:06