Last active
August 29, 2015 14:14
-
-
Save paulinamarczak/1ea05835ae85b5f51cd5 to your computer and use it in GitHub Desktop.
Must import packages: reshape2, ggplot2, lattice. Could not get Key/Legend to change colour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Define the datatset | |
CSV = data.frame(HTMLType = | |
factor(c("Metadata", "HTML Serialization", "Link to Download", | |
"Link and Metadata", "Landing Page", "Data Filter/Access Form", "Not Analyzed"), | |
levels = c("Metadata", "HTML Serialization", "Link to Download", "Link and Metadata", | |
"Landing Page", "Data Filter/Access Form","Not Analyzed")), | |
Australia = c(2.98,56.91,1.67,36.06,0.00,0.00,2.38), | |
Canada= c(0.49,13.13,6.04,39.03,0.00,0.00,41.31), | |
UnitedKingdom = c(4.99,0.00,0.00,23.92,3.96,0.00,67.13), | |
Ireland = c(0.00,5.65,34.00,0.00,4.55,0.00,55.80), | |
UnitedStates = c(26.98,6.65,14.27,0.00,6.24,9.53,36.33)) | |
#Make the dataset a list | |
CSV <- melt(CSV, id=c("HTMLType")) | |
#Plot the dataset in a matrix barplot | |
ggplot(CSV,aes(x=factor(HTMLType), y = value)) + | |
facet_wrap(~variable) + | |
geom_bar(stat="identity", aes(fill = factor(HTMLType))) | |
#Reorganize the structure and add legend using Lattice | |
#Could not figure out how to add another x axis on the top | |
barchart(~value|variable,group = factor(HTMLType),data=CSV, main= "HTML Type by Country", xlim=c(0,70), | |
scales=list(alternating=FALSE), layout=c(1,5), box.ratio=1, box.width=1, xlab= "Percent", col=colors, | |
#Legend: col=c("red","purple","yellow","green","blue", "orange", "light blue") changes the text colour only. | |
key = simpleKey(title= "Legend",levels(CSV$HTMLType), rectangles = TRUE,points = FALSE,space = "right", reverse= TRUE,)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment