[R] How to only show two numbers on bar_plot with ggplot

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Fri May 22 21:22:04 CEST 2020


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 <sokovic.anamarija using gmail.com> 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



More information about the R-help mailing list