Change the scale of only one axis in a plot with multiple Y axis

40 Views Asked by At

I have a dataframe that looks like this:

  Time                 Temp    DO Pump1 GasFlo    O2    pH  Agit Pump3
  <dttm>              <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl>
1 2023-08-08 22:00:00    37  134.     0    4.9     0  6.75  1200     0
2 2023-08-08 22:00:00    37  136.     0    4.9     0  6.75  1200     0
3 2023-08-08 22:01:00    37  132      0    4.9     0  6.75  1200     0
4 2023-08-08 22:01:00    37  134      0    4.9     0  6.75  1200     0
5 2023-08-08 22:02:00    37  134.     0    4.9     0  6.75  1200     0
6 2023-08-08 22:02:00    37  136.     0    4.9     0  6.75  1201     0

I want to plot the Time variable in the X axis and the rest of the variables each in a separate Y axis, this is what I am trying to recreate.

To make the code easier I only plotted three variables for the moment. This is my code:

highchart() %>%
  hc_chart(type = "line") %>%
  hc_xAxis(categories = rawdata$Time) %>%
  hc_yAxis_multiples(create_axis(naxis = 3),
                     list(title = list(text = "Base"),
                          lineWidth = 3,
                          showLastLabel = TRUE,
                          opposite = FALSE),
                     list(title = list(text = "DO"),
                          lineWidth = 3,
                          showLastLabel = TRUE,
                          opposite = FALSE),
                     list(title = list(text = "pH"),
                          lineWidth = 3,
                          showLastLabel = TRUE,
                          opposite = FALSE)) %>%
  hc_add_series(rawdata$Pump1, yAxis = 0, name = "Base") %>%
  hc_add_series(rawdata$DO, yAxis = 1, name = "%DO") %>%
  hc_add_series(rawdata$pH, yAxis = 2, name = "pH")    

Here's what the plot looks like. As you can see, one of the variables consists of a bunch of tall peaks one next to each other that make it a bit messy visually. I would like to change the scale of that variable in particular so that the peaks look smaller and don't take up that much space in the plot. The max value for that variable is 79.4 so I was thinking if I could make the range of the Y axis for that variable to be 0:300 the peaks would look much smaller. I tried the heights argument in create_axis (like putting, let's say, heights = c(1, 1, 2) but the plot looks the same no matter what combination of numbers I use, I suppose I may be using it incorrectly. I looked up in the package documentation but I can't find it. I don't know javascript so ideally I want to be able to solve this using just R.

0

There are 0 best solutions below