[R] How am i able to create Box plots of a factor (weight) separated by other factors (breed)?

John Kane jrkrideau at inbox.com
Sun Mar 15 13:53:39 CET 2015


As a follow up to Thierry's response.

With data as dat1

dat1  <-  structure(list(id = 1:12, weight = c(453L, 527L, 520L, 460L, 
496L, 461L, 519L, 472L, 531L, 473L, 509L, 503L), breed = c("brahman", 
"brahman", "brahman", "brahman", "durham", "durham", "durham", 
"durham", "durham", "durham", "durham", "durham")), .Names = c("id", 
"weight", "breed"), class = "data.frame", row.names = c(NA, -12L
))

library(ggplot2)
ggplot(dat1, aes(breed, weight)) +
      geom_boxplot()
library(ggplot2)
ggplot(dat1, aes(breed, weight)) +
      geom_boxplot()

I would note that it is difficult to break down the data by breed when your sample data only included brahman as a breed.  In the sample data above I changed a few entries to my favourite breed of Durham.

Have a look at one (or both) of these links for some useful suggestions on how to ask questions on R-help.  In particular, read about dput.  It is by far the best way to supply sample data for the readers.

Good luck

John Kane
Kingston ON Canada


> -----Original Message-----
> From: lyle00 at gmail.com
> Sent: Sun, 15 Mar 2015 14:50:22 +1100
> To: r-help at r-project.org
> Subject: [R] How am i able to create Box plots of a factor (weight)
> separated by other factors (breed)?
> 
>> 
>> 
>> I have data with columns for animal ID, breed, and weight.
>> 
>> I'd like to create a box plot of weight, separated by breed (there are 4
>> breeds).
>> 
>> Any ideas?
>> 
>> Here's a sample of the data (there are 100 rows):
>> 
>> id      weight  breed
>> 1       453     brahman
>> 2       527     brahman
>> 3       520     brahman
>> 4       460     brahman
>> 5       496     brahman
>> 6       461     brahman
>> 7       519     brahman
>> 8       472     brahman
>> 9       531     brahman
>> 10      473     brahman
>> 11      509     brahman
>> 12      503     brahman
>> 
>> Thanks for your help!
>> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!



More information about the R-help mailing list