Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot2 - How to boxplot two variables with different scales on same plot using a primary and secondary y-axis?
    primarykey
    data
    text
    <p>Datalink:</p> <p><a href="https://www.dropbox.com/s/kdi5uklhylr8vei/GTAP_DistEVYield.csv?m" rel="nofollow noreferrer">Data</a></p> <p>Code:</p> <pre><code> distevyield &lt;- read.csv(file = "F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/GTAP-CGE/GTAP_NewAggDatabase/NewFiles/GTAP_DistEVYield.csv", header=TRUE, sep=",", na.string="NA", dec=".", strip.white=TRUE) str(distevyield) distevyield &lt;- as.data.frame(distevyield) distevyield[5:6] &lt;- sapply(distevyield[5:6],as.numeric) distevyield &lt;- droplevels(distevyield) distevyield &lt;- transform(distevyield,region=factor(region,levels=unique(region))) library(ggplot2) distevyield.f &lt;- melt(subset(distevyield, region !="World")) Figure3 &lt;- ggplot(data = distevyield.f, aes(factor(variable), value)) Figure3 + geom_boxplot() + theme(axis.text.x = element_text(colour = 'black', angle = 90, size = 15, hjust = 1, vjust = 0.5),axis.title.x = element_blank()) + theme(axis.text.y = element_text(colour = 'black', size = 15, hjust = 0.5, vjust = 0.5), axis.title.y = element_blank()) + theme(strip.text.x = element_text(size = 14, hjust = 0.5, vjust = 0.5, face = 'bold')) + facet_wrap(~region, scales="free_y") </code></pre> <p>Outcome: <img src="https://i.stack.imgur.com/hktEk.png" alt="Plot result"></p> <p>Question:</p> <p>My two variables plotted, yield (%change) and ev (in million US$) have different units. Is there a way to add a secondary y-axis for one of the variable so as to display each variable with a boxplot representing its original units, but within the same plot? Does this feature exist in ggplot2 to begin with?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload