I have the following data
test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10))
I would like a barplot with 2 y axis (one for var.a, one for var.2). Each group (x axis, 1:10) should have 2 bars next to each other, one for var.a and one for var.b.
I cannot use one y-axis because of the difference morder of magnitude of var.a and var.b
Is this possible with base R?
Thank you
To use the
graphicspackage in R, one could create new variables as the values invar.aandvar.bconverted into proportions of the maximum values in the respective variable:Then draw the plot using
barplot()without the axes:Then add the axes on the left and the right using the original value ranges for the labels (the
labelsargument) and the proportional value ranges to place the labels on the axes (theatargument) (this part is not pretty, but it gets the job done):(Sorry for the lack of an image)
EDIT:
To get the axes a bit
prettyer,