How to make barplots of your data
- Download
your data and load it into R
- Simple
barplot of category
- barplot(table(stresschill$category))
- How
would you do subcategory?
- Make
the labels look prettier
- barplot(table(stresschill$category),
las=2, cex.names=0.6)
- las=2
rotates the labels
- cex.names=0.6
shrinks the label size
- Adding
color
- barplot(table(stresschill$category),
las=2, cex.names=0.6, col=c("blue","yellow"))
- Subseting
- chill
<- subset(stresschill,stress_value>0)
- barplot(table(chill$category),
las=2, cex.names=0.6, col=c("blue"))
- How
could you repeat this for stress and neutral data?
- Create
new categorical data with options of chill, neutral or stress based on
stress_value. Make a bar plot with
stress and category.
-
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)
- How
can you fix the labels and add color (blue, black, and red for example)?
- How
can you do this for subcategory?