Reputation: 531
I'm trying to make a graph to see the differences in student testing by age and their school rating. I could very easily make a normal scatterplot with student test scores by age and another for student test scores by school rating.
I could also make the graph with the school's rating on the x-axis, with age on one side of the y-axis and rating on the other. But while it's better than having two graphs -- it obviously doesn't show much more than that.
The idea here is that there is a correlation between not only school rating and test score, but also school rating and age -- so I'd like to figure out the best way to show that, since their age and rating both correlate with score. And a 16-year-old in a lower-rated school should be given more slack on their scores than a 16-year-old in a higher-rated school.
My original thought was that the x-axis would be the 1-10 ratings, while the test scores would be one y-axis and the age would be the z. But after looking it up for a while, I couldn't get surface3d()
to work or scatterplot3d()
, etc. These might've been functions I would need to load in -- but since I'm pretty new to R, I'm not sure. I'd be happy to download the correct package if somebody could point me in its direction.
A subset of this data looks like this:
Rating Score Age
1 54.911 13
1 85.665 18
3 66.246 13
3 83.103 17
3 88.556 17
3 80.631 18
4 90.562 17
4 77.799 14
4 78.771 16
5 87.912 17
6 92.113 15
7 89.275 15
7 93.556 16
7 63.177 16
7 78.258 18
8 76.116 14
9 96.351 18
9 85.06 16
9 85.664 17
10 88.487 15
There's the obvious possibility that I'm also thinking about this in the wrong way as well -- and I might have to switch my thought-process to learn how to make a bubble plot or something.
But all help and ideas are appreciated, thanks! (And sorry for partially asking two questions in one.)
Edit: Here's a quick graph in Excel with these values showing a positive correlation between both -- I'd just like a way to make it less messy and more intuitive:
Upvotes: 0
Views: 585
Reputation: 99341
It might look better in two dimensions, grouped by Age (or Rating). The lattice
package is nice for these types of plots. Anything can be adjusted. This one is colored by Age. Assuming your data is d
,
library(lattice)
xyplot(Rating ~ Score, data = d, groups = Age,
auto.key = list(title = "Age", space = "right", cex = 1.0),
par.settings = list(superpose.symbol = list(pch = 19, cex = 1)))
Upvotes: 1
Reputation: 145870
Calling your data df
, (I loaded it from your question in the clipboard)
df <- read.table(file = "clipboard", header = T)
Installing the package if you don't have it (If you do have it installed, just require(scatterplot3d)
will work)
if(!require(scatterplot3d)) {
install.packages("scatterplot3d")
require(scatterplot3d)
}
Make a plot
with(df, scatterplot3d(x = Rating, y = Age, z = Score))
A 3d plot isn't terrible here. You can also do 2d plots with color:
if(!require(ggplot2)) {
install.packages("ggplot2")
require(ggplot2)
}
ggplot(df, aes(x = Rating, y = Score, color = Age)) +
geom_point()
ggplot(df, aes(x = Age, y = Score, color = Rating)) +
geom_point()
Upvotes: 1