r - Barplot with Categorical X Axis -
i trying generate bar plot categorical x axis , 2 different y axis. trying use twoord.plot generate bar plot follows:
x <- c("a","b","c","d","e") ry <- c(0.1,0.2,0.3,0.4,0.5) ly <- c(0.15,0.25,0.35,0.45,0.55) library(plotrix) twoord.plot(x,ry,x,ly, xlab="xlabel", ylab="ylabel", rylab="rylabel", main="main", type=c("bar","l"),lcol=rainbow(length(x)),rcol=4)
however, getting error "error in plot.window(...) : invalid 'xlim' value".
is there way work categorical/character variables x-axis? also, there way rotate x-axis labels show @ 45 degrees?
i have been able code work following changes:
xnumeric <- seq(1:length(x)) twoord.plot(xnumeric,ly,xnumeric,ry, xlab="xlabel", ylab="ylabel", rylab="rylabel", main="main", type=c("bar","o"),lcol=rainbow(length(x)),rcol = 4,xticklab = x)
however, still need figure out how rotate x-axis labels adding legend differentiate between box plot , line plot. on appreciated
thank you.
this isn't in plotrix, but...
ry <- c(0.1,0.2,0.3,0.4,0.5) ly <- c(15,35,65,75,80) x <- 1:5 xlabs <- c("a","b","c","d","e") barplot(ly, xaxt="n", yaxt="n", xlab="xlabel", ylab="lylabel", ylim=c(0,100)) axis(2, seq(0,100,by=5), seq(0,100,by=5), las=2) # can adjust positions of ly labels par(new=true) plot(ry~x, xaxt="n", yaxt="n", xlab="", ylab="", ylim=c(0,1)) axis(1, 1:5, xlabs) axis(4, 1:10/10, 1:10/10, las=2) # can adjust positions of ry labels mtext("rylabel", 4, line=2)
and need edit bit colors, etc. seem going for.
Comments
Post a Comment