Barplot with Categorical X Axis

I am trying to generate a bar plot with a categorical X axis and two different y axis. I am trying to use twoord.plot to generate the bar plot as 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, I am getting an error "Error in plot.window(...) : invalid 'xlim' value".

Is there a way to work with categorical/character variables as x-axis? Also, is there a way to rotate the X-axis labels so that they show up at 45 degrees?

I have been able to get this code to work with the 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, I still need to figure out how to rotate the X-axis labels as well as adding a legend to differentiate between which is the box plot and which is the line plot. Any help on this would be appreciated

Thank you.

Answers


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) # you 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) # you can adjust positions of ry labels
mtext("ryLabel", 4, line=2)

And you would obviously need to edit a bit to get the colors, etc. that you seem to be going for.


Need Your Help

Print out prime Number less than a given number N

java algorithm data-structures time-complexity

Print out the prime numbers less than a given number N. For bonus points your solution should run in N*log(N) time or better. You may assume that N is always a positive integer.

How to improve end user experience and data reporting in web application?

web-applications reporting

I have a decent working web application (Java/Servlet/Jsp) that I would like to improve the end user experience and what they get out of using the application. I capture business data through html...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.