Hello, Below is the code for a basic bar graph. I was seeking advice regarding the following: (a) For each time period there are values from 16 people. How I can change the colour value so that each person has a different colour, which recurs across each of the three graphs/tie epriods? (b) I have seen much more sophisticated examples using lattice (e.g each person has a separate panel/plot). I am open to alternative code as to how I could present this data. Time1 <- c(9.0,6.0,1.0,5.0,7.0,9.0,5.0,7.5,6.0,8.0,5.0,5.0,9.0,4.0,5.0,5.0) Time2 <- c (10,5,3,3,3,6,7,8,5,8,7,7,9,8,5,3) Time3 <- c (10,0,3,0,0,6,0,0,0,0,0,0,0,0,0,0) df <- rbind (Time1, Time2, Time3) dft <- (t(df)) dft barplot(dft, beside = TRUE, main= "Risk score by assessment", xlab = " Score", ylab = "frequency", col="blue") Any assistance is much appreciated, regards Bob Green
improving a bar graph
5 messages · Bob Green, Jim Lemon, Gabor Grothendieck +2 more
Bob Green wrote:
Hello, Below is the code for a basic bar graph. I was seeking advice regarding the following: (a) For each time period there are values from 16 people. How I can change the colour value so that each person has a different colour, which recurs across each of the three graphs/tie epriods? (b) I have seen much more sophisticated examples using lattice (e.g each person has a separate panel/plot). I am open to alternative code as to how I could present this data. Time1 <- c(9.0,6.0,1.0,5.0,7.0,9.0,5.0,7.5,6.0,8.0,5.0,5.0,9.0,4.0,5.0,5.0) Time2 <- c (10,5,3,3,3,6,7,8,5,8,7,7,9,8,5,3) Time3 <- c (10,0,3,0,0,6,0,0,0,0,0,0,0,0,0,0) df <- rbind (Time1, Time2, Time3) dft <- (t(df)) dft barplot(dft, beside = TRUE, main= "Risk score by assessment", xlab = " Score", ylab = "frequency", col="blue")
Hi Bob, library(plotrix) barplot(dft, beside = TRUE, main= "Risk score by assessment", xlab = " Score", ylab = "frequency", col=color.scale(1:16,c(1,0.5,0),c(0,1,0),c(0,0.5,1))) legend(44,9,1:16, fill=color.scale(1:16,c(1,0.5,0),c(0,1,0),c(0,0.5,1))) Jim
Try this: matplot(t(dft), type = "o", xlab = "Time", ylab = "Score")
On Dec 16, 2007 4:14 AM, Bob Green <bgreen at dyson.brisnet.org.au> wrote:
Hello, Below is the code for a basic bar graph. I was seeking advice regarding the following: (a) For each time period there are values from 16 people. How I can change the colour value so that each person has a different colour, which recurs across each of the three graphs/tie epriods? (b) I have seen much more sophisticated examples using lattice (e.g each person has a separate panel/plot). I am open to alternative code as to how I could present this data. Time1 <- c(9.0,6.0,1.0,5.0,7.0,9.0,5.0,7.5,6.0,8.0,5.0,5.0,9.0,4.0,5.0,5.0) Time2 <- c (10,5,3,3,3,6,7,8,5,8,7,7,9,8,5,3) Time3 <- c (10,0,3,0,0,6,0,0,0,0,0,0,0,0,0,0) df <- rbind (Time1, Time2, Time3) dft <- (t(df)) dft barplot(dft, beside = TRUE, main= "Risk score by assessment", xlab = " Score", ylab = "frequency", col="blue") Any assistance is much appreciated, regards Bob Green
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Ugly brute-force approach: col=1:16 . Jim Lemon's approach with Plotrix is much nicer. You might also want to have a look at RColorBrewer though I am not sure how easily it can handle 16 different colours. barplot(dft, beside = TRUE, main= "Risk score by assessment", xlab = " Score", ylab = "frequency", col=1:16)
--- Bob Green <bgreen at dyson.brisnet.org.au> wrote:
Hello, Below is the code for a basic bar graph. I was seeking advice regarding the following: (a) For each time period there are values from 16 people. How I can change the colour value so that each person has a different colour, which recurs across each of the three graphs/tie epriods? (b) I have seen much more sophisticated examples using lattice (e.g each person has a separate panel/plot). I am open to alternative code as to how I could present this data. Time1 <-
c(9.0,6.0,1.0,5.0,7.0,9.0,5.0,7.5,6.0,8.0,5.0,5.0,9.0,4.0,5.0,5.0)
Time2 <- c (10,5,3,3,3,6,7,8,5,8,7,7,9,8,5,3) Time3 <- c (10,0,3,0,0,6,0,0,0,0,0,0,0,0,0,0) df <- rbind (Time1, Time2, Time3) dft <- (t(df)) dft barplot(dft, beside = TRUE, main= "Risk score by assessment", xlab = " Score", ylab = "frequency", col="blue") Any assistance is much appreciated, regards Bob Green
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On 12/16/07, Bob Green <bgreen at dyson.brisnet.org.au> wrote:
Hello, Below is the code for a basic bar graph. I was seeking advice regarding the following: (a) For each time period there are values from 16 people. How I can change the colour value so that each person has a different colour, which recurs across each of the three graphs/tie epriods? (b) I have seen much more sophisticated examples using lattice (e.g each person has a separate panel/plot). I am open to alternative code as to how I could present this data.
Why not use a line plot? It would be much easier to see how an individual is changing over time. Here's a simple way to do that using ggplot2: df <- data.frame(Time1, Time2, Time3) df$id <- 1:nrow(df) dfm <- melt(df, id="id") qplot(variable, value, data=dfm, group=id, geom="line") Hadley