How to make barplots of your data

 

  1. Download your data and load it into R
  2. Simple barplot of category
    1. barplot(table(stresschill$category))
    2. How would you do subcategory?
  3. Make the labels look prettier
    1. barplot(table(stresschill$category), las=2, cex.names=0.6)
    2. las=2 rotates the labels
    3. cex.names=0.6 shrinks the label size
  4. Adding color
    1. barplot(table(stresschill$category), las=2, cex.names=0.6, col=c("blue","yellow"))
  5. Subseting
    1. chill <- subset(stresschill,stress_value>0)
    2. barplot(table(chill$category), las=2, cex.names=0.6, col=c("blue"))
    3. How could you repeat this for stress and neutral data?
  6. Create new categorical data with options of chill, neutral or stress based on stress_value.  Make a bar plot with stress and category.
    1.  

stresschill$stress[stresschill$stress_value>0]<-"chill"

stresschill$stress[stresschill$stress_value==0]<-"neutral"

stresschill$stress[stresschill$stress_value<0]<-"stress"

stresschill$stress<-factor(as.character(stresschill$stress))

barplot(table(stresschill$stress,stresschill$category), legend=T, beside=T)

 

    1. How can you fix the labels and add color (blue, black, and red for example)?
    2. How can you do this for subcategory?