4
$\begingroup$

I have some survey data, where the first question is something like, "rate how you are feeling on a scale of 1 - 5". The next group of questions are something like, "do you smoke?" or "how much exercise do you get per day: 0, 15, 30, 45, 60, 60+?"

I'm looking for a way to visualize this data, where each question is compared to how the the surveyor is feeling. Any suggestions? I came across a correlation matrix, but it seems I can't have how you are feeling scale on the x-axis and the questions on the y-axis.

feeling_scale,  smokes,  exercise_frequency
5,              N,       15
3,              Y,       60
5,              Y,        0
$\endgroup$
5
  • 1
    $\begingroup$ Yes, I'm sure you can. If you made a reproducible example it might be possible to answer your question. $\endgroup$
    – Andrie
    Aug 21, 2012 at 13:31
  • $\begingroup$ @Aaron thanks! That's the kind of stuff I was looking for. Perhaps my questions wasn't clear $\endgroup$
    – Bradford
    Aug 21, 2012 at 13:46
  • 4
    $\begingroup$ The downvotes are perhaps because 1) there's not sample data, and 2) you say you can't use a correlation matrix, but don't explain why you don't think so. It would have been more polite for the downvoters to explain why and give you a chance to fix it before downvoting. It's not necessarily a bad question; it just needs a little improvement. $\endgroup$ Aug 21, 2012 at 13:49
  • $\begingroup$ Thanks, Aaron. Valid points. I was trying to use corrplot, btw. I just couldn't figure it out and assumed it wasn't possible. Also, all the examples I saw had their x- and y-axis labels the same. $\endgroup$
    – Bradford
    Aug 21, 2012 at 13:50
  • 1
    $\begingroup$ More suggestions here: stats.stackexchange.com/q/3921/3601 and here: stats.stackexchange.com/q/25109/3601; I especially like the centered count one. (This comment was left previously but seems to have been lost in the migration; it's what the thanks above was for.) $\endgroup$ Aug 23, 2012 at 19:51

4 Answers 4

10
$\begingroup$

Try the lattice package and maybe box-and-whisker plots.

# Make up some data
set.seed(1)
test = data.frame(feeling_scale = sample(1:5, 50, replace=TRUE),
                  smokes = sample(c("Y", "N"), 50, replace=TRUE),
                  exercise_frequency = sample(seq(0, 60, 15), 
                                              50, replace = TRUE))
library(lattice)
bwplot(exercise_frequency ~ feeling_scale | smokes, test)

enter image description here

I would also think that a basic barchart would be fine for this type of data.

barchart(xtabs(feeling_scale ~ exercise_frequency + smokes, test), 
         stack=FALSE, horizontal=FALSE, auto.key=list(space = "right"))

enter image description here

A third option I can think of is the bubble plot, but I'll leave it up to you to decide on how to scale the circles appropriately. It also requires that you first get the frequencies of the different combinations of exercise_frequency and feeling_scale.

test2 = data.frame(with(test, 
                        table(feeling_scale,
                              exercise_frequency, smokes)))
par(mfrow = c(1, 2))
lapply(split(test2, test2$smokes), 
       function(x) symbols(x$feeling_scale, x$exercise_frequency, 
                           circles = x$Freq, inches=1/4))

enter image description here

$\endgroup$
1
$\begingroup$

I am thinking that you could simply summarize the data in a contingency table. The columns could be the question numbers and the rows the specific answers. The ij$^t$$^h$ cell would contain the number of responses to question i with response j.

$\endgroup$
0
$\begingroup$

Could you just use a pie chart? Each category would be one piece of the pie and it's size would be the proportion it represents of the total.

$\endgroup$
1
  • $\begingroup$ I would then have to show a pie chart at productivity=1, productivity=2, ..., productivity=5 for each question, right? I'm looking for less. $\endgroup$
    – Bradford
    Aug 21, 2012 at 13:37
0
$\begingroup$

I like the conditional boxplots from lattice, but.. I prefer base graphics so I thought I would throw this on here.

par(mar=c(1.1,4.1,4.1,2.1))
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
boxplot(test$exercise_frequency~as.factor(test$feeling_scale), main="Overall")
boxplot(test$exercise_frequency[test$smokes == "Y"]~as.factor(test$feeling_scale[test$smokes == "Y"]), 
        main="Smokers")
boxplot(test$exercise_frequency[test$smokes == "N"]~as.factor(test$feeling_scale[test$smokes == "N"]), 
        main="Non-Smokers")

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.