Lyle Warren
2015-Mar-15 03:50 UTC
[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]]
Thierry Onkelinx
2015-Mar-15 08:18 UTC
[R] How am i able to create Box plots of a factor (weight) separated by other factors (breed)?
Have a look at http://docs.ggplot2.org/current/geom_boxplot.html You will find several examples there. Best regards Op 15-mrt.-2015 04:59 schreef "Lyle Warren" <lyle00 at gmail.com>:> > > > > > 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. >[[alternative HTML version deleted]]
Rui Barradas
2015-Mar-15 11:45 UTC
[R] How am i able to create Box plots of a factor (weight) separated by other factors (breed)?
Hello, Try, if your data.frame is named 'animal', boxplot(weight ~ breed, data = animal) Hope this helps, Rui Barradas Em 15-03-2015 03:50, Lyle Warren escreveu:>> >> >> 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. >
John Kane
2015-Mar-15 12:53 UTC
[R] How am i able to create Box plots of a factor (weight) separated by other factors (breed)?
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!
Rich Shepard
2015-Mar-15 12:55 UTC
[R] How am i able to create Box plots of a factor (weight) separated by other factors (breed)?
On Sun, 15 Mar 2015, Lyle Warren wrote:>> 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?1. Did you check the help page: ?boxplot>> 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 brahmanB. Perhaps something like this? boxplot(weight ~ breed) Look at the use of a formula when plotting. If I misread your intent I apologize. HTH, Rich