How to only show two numbers on bar_plot with ggplot

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

How to only show two numbers on bar_plot with ggplot

anikaM
Hello,

I made the plot in attach via:

ed<-ggplot(e) +
  geom_bar(aes(x = ESRD, fill =
factor(pheno,labels=c("control","case"))))+scale_fill_manual(values=c("#56B4E9","#E7B800"))+labs(fill="pheno")

ed

How do I show only 1 and 2 on x axis?

Thanks
Ana

______________________________________________
[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.

Screen Shot 2020-05-22 at 1.50.21 PM.png (66K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to only show two numbers on bar_plot with ggplot

anikaM
I resolved it not elegantly with:

d=as.numeric(as.character(e$pheno))
ed<-ggplot(e) +
  geom_bar(aes(x = ESRD, fill =
factor(pheno,labels=c("control","case"))))+scale_fill_manual(values=c("#56B4E9","#E7B800"))+labs(fill="pheno")+scale_x_continuous(breaks
= unique(d))

ed

where:

> head(e)
  ESRD pheno
1    1     1
2    1     1
3    1     2
4    1     1
5    1     1

> sapply(e,class)
     ESRD     pheno
"integer"  "factor"

On Fri, May 22, 2020 at 1:52 PM Ana Marija <[hidden email]> wrote:

>
> Hello,
>
> I made the plot in attach via:
>
> ed<-ggplot(e) +
>   geom_bar(aes(x = ESRD, fill =
> factor(pheno,labels=c("control","case"))))+scale_fill_manual(values=c("#56B4E9","#E7B800"))+labs(fill="pheno")
>
> ed
>
> How do I show only 1 and 2 on x axis?
>
> Thanks
> Ana

______________________________________________
[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: How to only show two numbers on bar_plot with ggplot

Rui Barradas
Hello,

Why not remove aes(x = ESRD,...) from the call to geom_bar and instead do

ed <- ggplot(e, aes(x = factor(ESRD)) + etc?


If you are using an aesthetic throughout the plot, put it in the call to
ggplot().

Hope this helps,

Rui Barradas

Às 20:22 de 22/05/20, Ana Marija escreveu:

> I resolved it not elegantly with:
>
> d=as.numeric(as.character(e$pheno))
> ed<-ggplot(e) +
>    geom_bar(aes(x = ESRD, fill =
> factor(pheno,labels=c("control","case"))))+scale_fill_manual(values=c("#56B4E9","#E7B800"))+labs(fill="pheno")+scale_x_continuous(breaks
> = unique(d))
>
> ed
>
> where:
>
>> head(e)
>    ESRD pheno
> 1    1     1
> 2    1     1
> 3    1     2
> 4    1     1
> 5    1     1
>
>> sapply(e,class)
>       ESRD     pheno
> "integer"  "factor"
>
> On Fri, May 22, 2020 at 1:52 PM Ana Marija <[hidden email]> wrote:
>>
>> Hello,
>>
>> I made the plot in attach via:
>>
>> ed<-ggplot(e) +
>>    geom_bar(aes(x = ESRD, fill =
>> factor(pheno,labels=c("control","case"))))+scale_fill_manual(values=c("#56B4E9","#E7B800"))+labs(fill="pheno")
>>
>> ed
>>
>> How do I show only 1 and 2 on x axis?
>>
>> Thanks
>> Ana
>
> ______________________________________________
> [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.