I’m looking to a scatter plot with a rotated X axis. Basically, I want to plot correlations between 2 Y-axes. Ideally, I’d like to have the x-axis represent the time and Y-axes represent the correlations
data <- data.frame( words = c( "Aliens", "Aliens", "Constitution", "Constitution", "Entitled", "Entitled" ),
dates = as.Date( c ("2010-01-05", "2010-02-13", "2010-04-20", "2010-06-11","2010-03-18", "2010-09-13" )),
Rep = c( .18, .14, .16, .45, .33, .71 ), Dem = c( .16, .38, .24, .11, .59, .34 ))
And this is what I was able to do so far. I don’t think it really gets the point across. I could size by correlation and color by month?
plot(x=data$dates, y=data$Rep, ylim=c(0,1.1*max(data$Rep)),
col='blue', pch = 15,
main='Rep Correlations stock close', xlab='date', ylab='Republican')
axis(2, pretty(c(0, 1.1*max(data$Rep))), col='blue')
par(new=T)
plot(x=data$date, y=data$Dem, ylim=c(0,1.1*max(data$Dem)),
col='green', pch = 20,
xaxt='n', axes = F, xlab = '', ylab='')
axis(4, pretty(c(0, 1.1*max(data$Dem))), col='green')
mtext("Democrat",side=4)
Any thoughts/tips?
Following up on @JohnColby’s comment above (and see How can I plot with 2 different y-axes? , http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:2yaxes for arguments why you should not create dual y-axis plots if you can help it ), how about:
(adding lines between the points, then re-plotting the points so they’re not obscured by the line; adding the words is cute but might be too much clutter for the full data set)
Or encode date as a continuous variable
In this particular context (where both variables are measured on the same scale), there’s also nothing wrong with plotting them both against the date axis: