Plotting 3 Y axis vs x
1
0
Entering edit mode
16 months ago
WUSCHEL ▴ 800

How to plot 3 Y axis in single plot? is is possible in ggplot2?

Something like this enter image description here Here is my dummy data

structure(list(Season = c("2019/2020", "2020/2021", "2021/2022", 
"2022/2023"), `Area (1000 Ha)` = c(973, 1085, 1130, 1090), `Production (1000 Tons)` = c(3207, 
3390, 2733, 2525), `Yield (T/Ha)` = c(4.8, 4.6, 3.6, 3.4)), row.names = c(NA, 
-4L), spec = structure(list(cols = list(Season = structure(list(), class = c("collector_character", 
"collector")), `Area (1000 Ha)` = structure(list(), class = c("collector_double", 
"collector")), `Production (1000 Tons)` = structure(list(), class = c("collector_double", 
"collector")), `Yield (T/Ha)` = structure(list(), class = c("collector_double", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x000001a36b215550>, class = c("spec_tbl_df", 
"tbl_df", "tbl", "data.frame"))
r ggplot2 • 664 views
ADD COMMENT
6
Entering edit mode
16 months ago

Since a while, ggplot2 supports the sec.axis parameter for continuous scales, which allows you to have a second axis that is a transformation of the primary one. For example, this blog post illustrates the use.

I am not aware of a simple way to have three axes, and also suggest choosing a different visualization. I think, there are good reasons to opt for two axes at times, for example when your audience is used to different units of measurement (kilometres and miles, degrees Celsius and Fahrenheit etc.). However, it is hard to image a reason for three axes.

Consider the plot above: Can you approximately draw it by hand from memory? What is its key message?

Maybe I am just speaking for myself here, but I wouldn't be able to recall how the output changed over time during the year 2014. Is there a relationship of output with cost or not? Is there a seasonal trend, or are values just randomly changing over time? Neither of this I can tell from your plot.

So I strongly recommend to not look for ways to display three trend lines in one plot and use facets instead. Also focus on a potential relationship between the data on display. Generalized additive models are very well suited to capture both, long-term trends and seasonal patterns in time-series data! In your particular case, the yield is production normalized to area and there is no reason to put that back into one plot with the raw values. Besides GAMs, also consider binning, distributions etc. to emphasize trends and ultimately tell the story of what one can see in the data.

ADD COMMENT

Login before adding your answer.

Traffic: 3642 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6