ggplot and boxplots

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ggplot and boxplots

R help mailing list-2
Hi,

I was wondering if someone could give me a hint or two. I'm having problems generating ggplot2 boxplots . The plot that is has dots but no boxplots. Below is the dataset

> testing_ggplot
    V1        V2     V3
1  256  Disabled 688.61
2  256  Disabled 698.63
3  256  Disabled 700.02
4  256  Disabled 693.36
5  256  Disabled  688.8
6  256  Disabled 697.72
7  256  Disabled 698.15
8  256  Disabled 693.98
9  256  Disabled 700.75
...
16 256   Enabled 698.35
17 256   Enabled 694.71
18 256   Enabled 705.53
19 256   Enabled 708.61
20 256   Enabled 693.33
...
32 272  Disabled 690.79

33 272  Disabled 687.14
34 272  Disabled 684.92
35 272  Disabled 687.87
36 272  Disabled 687.33
37 272   Enabled 696.22
38 272   Enabled 700.61
39 272   Enabled  695.2
40 272   Enabled 697.46
41 272   Enabled 696.83
...

This command for some reason, fails to generate a boxplot
> ggplot(testing_ggplot,aes(factor(V2),V3))+geom_boxplot() +facet_wrap(~as.factor(V1))

I don't seem to figure out what is wrong with the ggplot command I'm using. I attached a png with the generated plot

thanks,

yh
______________________________________________
[hidden email] 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.

ggplot.png (83K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: ggplot and boxplots

Richard M. Heiberger
It looks like your V3 is a factor.

testing_ggplot <- data.frame(
  V1=factor(c(256, 256, 256, 272, 272, 272)),
  V2=c("Disabled", "Disabled", "Enabled", "Disabled", "Enabled", "Enabled"),
  V3=681:686)

library(ggplot2)
ggplot(testing_ggplot, aes(V2,        V3 )) + geom_boxplot() +
facet_wrap( ~ V1) + labs(title="what you want")
ggplot(testing_ggplot, aes(V2, factor(V3))) + geom_boxplot() +
facet_wrap( ~ V1) + labs(title="what you are getting")

On Mon, Mar 12, 2018 at 4:28 PM, Yectli Huerta via R-help
<[hidden email]> wrote:

> Hi,
>
> I was wondering if someone could give me a hint or two. I'm having problems generating ggplot2 boxplots . The plot that is has dots but no boxplots. Below is the dataset
>
>> testing_ggplot
>     V1        V2     V3
> 1  256  Disabled 688.61
> 2  256  Disabled 698.63
> 3  256  Disabled 700.02
> 4  256  Disabled 693.36
> 5  256  Disabled  688.8
> 6  256  Disabled 697.72
> 7  256  Disabled 698.15
> 8  256  Disabled 693.98
> 9  256  Disabled 700.75
> ...
> 16 256   Enabled 698.35
> 17 256   Enabled 694.71
> 18 256   Enabled 705.53
> 19 256   Enabled 708.61
> 20 256   Enabled 693.33
> ...
> 32 272  Disabled 690.79
>
> 33 272  Disabled 687.14
> 34 272  Disabled 684.92
> 35 272  Disabled 687.87
> 36 272  Disabled 687.33
> 37 272   Enabled 696.22
> 38 272   Enabled 700.61
> 39 272   Enabled  695.2
> 40 272   Enabled 697.46
> 41 272   Enabled 696.83
> ...
>
> This command for some reason, fails to generate a boxplot
>> ggplot(testing_ggplot,aes(factor(V2),V3))+geom_boxplot() +facet_wrap(~as.factor(V1))
>
> I don't seem to figure out what is wrong with the ggplot command I'm using. I attached a png with the generated plot
>
> thanks,
>
> yh
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: ggplot and boxplots

R help mailing list-2

On March 12, 2018 11:59 PM, Richard M. Heiberger <[hidden email]> wrote:

> It looks like your V3 is a factor.
>
> testing_ggplot <- data.frame(
>
> V1=factor(c(256, 256, 256, 272, 272, 272)),
>
> V2=c("Disabled", "Disabled", "Enabled", "Disabled", "Enabled", "Enabled"),
>
> V3=681:686)
>

thanks for the explanation and solution.

yah

______________________________________________
[hidden email] 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.