0

I have seen a lot of answers to questions regarding secondary axes but they all seem to be transformations of the data being presented for the primary axis, usually for data that is directly related.

I have two data frames that entirely different that I am trying to determine if a relationship exists. My first data frame is daily River Stage measurements and my second is chemical data from a sample taken in the middle of the month.

My first DF - River is as follows (sample below):

   Date        River_stage
   1/1/23      424
   1/15/23     424.5
   1/30/23     425

My second DF - Sample is as follows (sample below):

   Date       Chemical         Unit
   1/15/23    15               Unit_1
   1/15/23    10               Unit_2
   1/15/23    5                Unit_3

My goal is to have the geom_boxplot on the primary y-axis and the river stage on the secondary y-axis. I understand that I may also need to use two separate x-axes as well because the boxplot data may be squished. I am not the best with secondary axes, mainly because I understand that they need be transformed from the primary axis but is there anyway to do it with my data?

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
JackWassik
  • 65
  • 6
  • As the existing questions point out, you need to transform your data. ggplot does not support two arbitrary y-scales because that almost always leads to misleading plots. In this example it's not clear what your desired output is. I'm not sure what type of box plot you are trying to make with so little data. Maybe just create two separate plots and put them side by side. – MrFlick Apr 24 '23 at 21:05
  • The data I provided is not the exact data, it is merely an example dataset. I apologize that it was not clear but I wanted the river data to be in geom_line on the secondary axis. – JackWassik Apr 25 '23 at 12:06

0 Answers0