editing plot

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

editing plot

anikaM
Hello,

I have this plot in attach. I was wondering how can I change my
plotting code in order to remove these gray horizontal background
lines but keep these two vertical lines? These two vertical lines
don't need to be gray, can be any other type of lines but they must be
at the same place. Also how can I make these two bars narrower?

library("ggplot2")
p<-ggplot(data=toplot, aes(x=cat, y=props)) +
  geom_bar(stat="identity", fill="steelblue")+
  geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.2,
                position=position_dodge(.9))  +

  geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
                               c("All SNPs", "eQTL from 103 genes")),
              y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
= 0.0012", "p = 0.0023")) +
  scale_y_continuous(breaks=seq(0,.06,by=.01)) +
  xlab("") + ylab("Proportion p-values < 0.05") +
  theme_minimal()
p

______________________________________________
[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-01-08 at 12.51.34 PM.png (88K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: editing plot

anikaM
I used width=0.5, to reduce bar widths and aspect.ratio = 2/1 to
reduce white spaces between bars but now text on my x axis is
overlapping and my plot is too elongated, and I don't have those 3
vertical lines trough bars.

Please advise

p<-ggplot(data=toplot, aes(x=cat, y=props)) +
  geom_bar(stat="identity",width=0.5, fill="steelblue")+
  geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.1,
                position=position_dodge(.9))  +

  geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
                               c("All SNPs", "eQTL from 103 genes")),
              y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
= 0.0012", "p = 0.0023")) +
  scale_y_continuous(breaks=seq(0,.06,by=.01)) +
  xlab("") + ylab("Proportion p-values < 0.05") +
  theme(aspect.ratio = 2/1,axis.title.x=element_text(size=1,face="bold"))
p

On Wed, Jan 8, 2020 at 12:52 PM Ana Marija <[hidden email]> wrote:

>
> Hello,
>
> I have this plot in attach. I was wondering how can I change my
> plotting code in order to remove these gray horizontal background
> lines but keep these two vertical lines? These two vertical lines
> don't need to be gray, can be any other type of lines but they must be
> at the same place. Also how can I make these two bars narrower?
>
> library("ggplot2")
> p<-ggplot(data=toplot, aes(x=cat, y=props)) +
>   geom_bar(stat="identity", fill="steelblue")+
>   geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.2,
>                 position=position_dodge(.9))  +
>
>   geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
>                                c("All SNPs", "eQTL from 103 genes")),
>               y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> = 0.0012", "p = 0.0023")) +
>   scale_y_continuous(breaks=seq(0,.06,by=.01)) +
>   xlab("") + ylab("Proportion p-values < 0.05") +
>   theme_minimal()
> p

______________________________________________
[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: editing plot

anikaM
I made some progress with this:
ax.11.text <- element_text(size = 10)
ay.11.text <- element_text(size = 10)
p<-ggplot(data=toplot, aes(x=cat, y=props)) +
  geom_bar(stat="identity",width=0.5, fill="steelblue")+
  geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.1,
                position=position_dodge(.9))  +

  geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
                               c("All SNPs", "eQTL from 103 genes")),
              y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
= 0.0012", "p = 0.0023")) +
  scale_y_continuous(breaks=seq(0,.06,by=.01)) +
  xlab("") + ylab("Proportion p-values < 0.05") +
  theme_classic()+
  theme(aspect.ratio = 2/1,axis.text.x = ax.11.text,axis.text.y=ay.11.text)
p

But the spaces between ticks on y axis are too big and the plot is
very elongated. Any advice on how to shrink this vertically?



On Wed, Jan 8, 2020 at 1:14 PM Ana Marija <[hidden email]> wrote:

>
> I used width=0.5, to reduce bar widths and aspect.ratio = 2/1 to
> reduce white spaces between bars but now text on my x axis is
> overlapping and my plot is too elongated, and I don't have those 3
> vertical lines trough bars.
>
> Please advise
>
> p<-ggplot(data=toplot, aes(x=cat, y=props)) +
>   geom_bar(stat="identity",width=0.5, fill="steelblue")+
>   geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.1,
>                 position=position_dodge(.9))  +
>
>   geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
>                                c("All SNPs", "eQTL from 103 genes")),
>               y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> = 0.0012", "p = 0.0023")) +
>   scale_y_continuous(breaks=seq(0,.06,by=.01)) +
>   xlab("") + ylab("Proportion p-values < 0.05") +
>   theme(aspect.ratio = 2/1,axis.title.x=element_text(size=1,face="bold"))
> p
>
> On Wed, Jan 8, 2020 at 12:52 PM Ana Marija <[hidden email]> wrote:
> >
> > Hello,
> >
> > I have this plot in attach. I was wondering how can I change my
> > plotting code in order to remove these gray horizontal background
> > lines but keep these two vertical lines? These two vertical lines
> > don't need to be gray, can be any other type of lines but they must be
> > at the same place. Also how can I make these two bars narrower?
> >
> > library("ggplot2")
> > p<-ggplot(data=toplot, aes(x=cat, y=props)) +
> >   geom_bar(stat="identity", fill="steelblue")+
> >   geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.2,
> >                 position=position_dodge(.9))  +
> >
> >   geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
> >                                c("All SNPs", "eQTL from 103 genes")),
> >               y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> > = 0.0012", "p = 0.0023")) +
> >   scale_y_continuous(breaks=seq(0,.06,by=.01)) +
> >   xlab("") + ylab("Proportion p-values < 0.05") +
> >   theme_minimal()
> > p

______________________________________________
[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-01-08 at 1.36.25 PM.png (143K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: editing plot

Rui Barradas
In reply to this post by anikaM
Hello,

Maybe


theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
         panel.grid.major.y = element_blank(),
         panel.grid.minor = element_blank()
   )



Note that if you remove the y axis grid you must set the x axis grid
explicitly.

Hope this helps,

Rui Barradas

Às 18:52 de 08/01/20, Ana Marija escreveu:

> Hello,
>
> I have this plot in attach. I was wondering how can I change my
> plotting code in order to remove these gray horizontal background
> lines but keep these two vertical lines? These two vertical lines
> don't need to be gray, can be any other type of lines but they must be
> at the same place. Also how can I make these two bars narrower?
>
> library("ggplot2")
> p<-ggplot(data=toplot, aes(x=cat, y=props)) +
>    geom_bar(stat="identity", fill="steelblue")+
>    geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.2,
>                  position=position_dodge(.9))  +
>
>    geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
>                                 c("All SNPs", "eQTL from 103 genes")),
>                y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> = 0.0012", "p = 0.0023")) +
>    scale_y_continuous(breaks=seq(0,.06,by=.01)) +
>    xlab("") + ylab("Proportion p-values < 0.05") +
>    theme_minimal()
> p
>
>
> ______________________________________________
> [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: editing plot

anikaM
HI Rui,

Thank you so much for getting back to me!
I did implement your idea (see attach):

ax.11.text <- element_text(size = 10)
ay.11.text <- element_text(size = 10)
p<-ggplot(data=toplot, aes(x=cat, y=props)) +
  geom_bar(stat="identity",width=0.5, fill="steelblue")+
  geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.1,
                position=position_dodge(.9))  +

  geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
                               c("All SNPs", "eQTL from 103 genes")),
              y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
= 0.0012", "p = 0.0023")) +
  scale_y_continuous(breaks=seq(0,.06,by=.01)) +
  xlab("") + ylab("Proportion p-values < 0.05") +
  theme_classic()+
  theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
        panel.grid.major.y = element_blank(),
        panel.grid.minor = element_blank(),axis.text.x =
ax.11.text,axis.text.y=ay.11.text
  )
p

I was wondering is there is any way to decrease the amount of white
spaces around the bars?

Thanks
Ana

On Wed, Jan 8, 2020 at 2:58 PM Rui Barradas <[hidden email]> wrote:

>
> Hello,
>
> Maybe
>
>
> theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
>          panel.grid.major.y = element_blank(),
>          panel.grid.minor = element_blank()
>    )
>
>
>
> Note that if you remove the y axis grid you must set the x axis grid
> explicitly.
>
> Hope this helps,
>
> Rui Barradas
>
> Às 18:52 de 08/01/20, Ana Marija escreveu:
> > Hello,
> >
> > I have this plot in attach. I was wondering how can I change my
> > plotting code in order to remove these gray horizontal background
> > lines but keep these two vertical lines? These two vertical lines
> > don't need to be gray, can be any other type of lines but they must be
> > at the same place. Also how can I make these two bars narrower?
> >
> > library("ggplot2")
> > p<-ggplot(data=toplot, aes(x=cat, y=props)) +
> >    geom_bar(stat="identity", fill="steelblue")+
> >    geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.2,
> >                  position=position_dodge(.9))  +
> >
> >    geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
> >                                 c("All SNPs", "eQTL from 103 genes")),
> >                y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> > = 0.0012", "p = 0.0023")) +
> >    scale_y_continuous(breaks=seq(0,.06,by=.01)) +
> >    xlab("") + ylab("Proportion p-values < 0.05") +
> >    theme_minimal()
> > p
> >
> >
> > ______________________________________________
> > [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.

Screen Shot 2020-01-09 at 10.38.42 AM.png (164K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: editing plot

anikaM
HI Rui,

Thank you so much for getting back to me!
I did implement your idea (see attach):

ax.11.text <- element_text(size = 10)
ay.11.text <- element_text(size = 10)
p<-ggplot(data=toplot, aes(x=cat, y=props)) +
  geom_bar(stat="identity",width=0.5, fill="steelblue")+
  geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.1,
                position=position_dodge(.9))  +

  geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
                               c("All SNPs", "eQTL from 103 genes")),
              y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
= 0.0012", "p = 0.0023")) +
  scale_y_continuous(breaks=seq(0,.06,by=.01)) +
  xlab("") + ylab("Proportion p-values < 0.05") +
  theme_classic()+
  theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
        panel.grid.major.y = element_blank(),
        panel.grid.minor = element_blank(),axis.text.x =
ax.11.text,axis.text.y=ay.11.text
  )
p

I was wondering is there is any way to decrease the amount of white
spaces around the bars?

Thanks
Ana

On Thu, Jan 9, 2020 at 10:41 AM Ana Marija <[hidden email]> wrote:

>
> HI Rui,
>
> Thank you so much for getting back to me!
> I did implement your idea (see attach):
>
> ax.11.text <- element_text(size = 10)
> ay.11.text <- element_text(size = 10)
> p<-ggplot(data=toplot, aes(x=cat, y=props)) +
>   geom_bar(stat="identity",width=0.5, fill="steelblue")+
>   geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.1,
>                 position=position_dodge(.9))  +
>
>   geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
>                                c("All SNPs", "eQTL from 103 genes")),
>               y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> = 0.0012", "p = 0.0023")) +
>   scale_y_continuous(breaks=seq(0,.06,by=.01)) +
>   xlab("") + ylab("Proportion p-values < 0.05") +
>   theme_classic()+
>   theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
>         panel.grid.major.y = element_blank(),
>         panel.grid.minor = element_blank(),axis.text.x =
> ax.11.text,axis.text.y=ay.11.text
>   )
> p
>
> I was wondering is there is any way to decrease the amount of white
> spaces around the bars?
>
> Thanks
> Ana
>
> On Wed, Jan 8, 2020 at 2:58 PM Rui Barradas <[hidden email]> wrote:
> >
> > Hello,
> >
> > Maybe
> >
> >
> > theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
> >          panel.grid.major.y = element_blank(),
> >          panel.grid.minor = element_blank()
> >    )
> >
> >
> >
> > Note that if you remove the y axis grid you must set the x axis grid
> > explicitly.
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Às 18:52 de 08/01/20, Ana Marija escreveu:
> > > Hello,
> > >
> > > I have this plot in attach. I was wondering how can I change my
> > > plotting code in order to remove these gray horizontal background
> > > lines but keep these two vertical lines? These two vertical lines
> > > don't need to be gray, can be any other type of lines but they must be
> > > at the same place. Also how can I make these two bars narrower?
> > >
> > > library("ggplot2")
> > > p<-ggplot(data=toplot, aes(x=cat, y=props)) +
> > >    geom_bar(stat="identity", fill="steelblue")+
> > >    geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.2,
> > >                  position=position_dodge(.9))  +
> > >
> > >    geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
> > >                                 c("All SNPs", "eQTL from 103 genes")),
> > >                y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> > > = 0.0012", "p = 0.0023")) +
> > >    scale_y_continuous(breaks=seq(0,.06,by=.01)) +
> > >    xlab("") + ylab("Proportion p-values < 0.05") +
> > >    theme_minimal()
> > > p
> > >
> > >
> > > ______________________________________________
> > > [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.

Screen Shot 2020-01-09 at 10.42.17 AM.png (90K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: editing plot

Rui Barradas
In reply to this post by anikaM
Hello,

There are ways of reducing the white space between the bars but they are
not obvious. Here are the two ways that I know.

First a data example.

library(ggplot2)
library(gridExtra)

df1 <- data.frame(x = LETTERS[1:5],
                   y = c(40, 15, 30, 15, 20))


1. The examples that follow set argument width in two places. What is
important is the relative magnitudes of width and position_dodge(width).

If width is bigger than position_dodge(width) then the bar sizes and the
space between them do not change. They only change if the second width
is bigger. In this case the first argument makes a difference. Run the
examples to see what I mean.


g1 <- ggplot(df1, aes(x, y)) +
   geom_bar(stat = "identity",
            width = 0.8,
            position = position_dodge(width = 0.5))

g2 <- ggplot(df1, aes(x, y)) +
   geom_bar(stat = "identity",
            width = 0.8,
            position = position_dodge(width = 0.25))

g3 <- ggplot(df1, aes(x, y)) +
   geom_bar(stat = "identity",
            width = 0.5,
            position = position_dodge(width = 0.8))

g4 <- ggplot(df1, aes(x, y)) +
   geom_bar(stat = "identity",
            width = 0.25,
            position = position_dodge(width = 0.8))

grid.arrange(g31, g2, g3, g4)


2. The other way is to shrink the plot by changing its aspect ratio.

g3 + theme(aspect.ratio = 2/1)

grid.arrange(g3, g3 + theme(aspect.ratio = 2/1), nrow = 1)


Run the examples and try to do something out of this.


Hope this helps,

Rui Barradas


Às 16:41 de 09/01/20, Ana Marija escreveu:

> HI Rui,
>
> Thank you so much for getting back to me!
> I did implement your idea (see attach):
>
> ax.11.text <- element_text(size = 10)
> ay.11.text <- element_text(size = 10)
> p<-ggplot(data=toplot, aes(x=cat, y=props)) +
>    geom_bar(stat="identity",width=0.5, fill="steelblue")+
>    geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.1,
>                  position=position_dodge(.9))  +
>
>    geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
>                                 c("All SNPs", "eQTL from 103 genes")),
>                y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
> = 0.0012", "p = 0.0023")) +
>    scale_y_continuous(breaks=seq(0,.06,by=.01)) +
>    xlab("") + ylab("Proportion p-values < 0.05") +
>    theme_classic()+
>    theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
>          panel.grid.major.y = element_blank(),
>          panel.grid.minor = element_blank(),axis.text.x =
> ax.11.text,axis.text.y=ay.11.text
>    )
> p
>
> I was wondering is there is any way to decrease the amount of white
> spaces around the bars?
>
> Thanks
> Ana
>
> On Wed, Jan 8, 2020 at 2:58 PM Rui Barradas <[hidden email]> wrote:
>>
>> Hello,
>>
>> Maybe
>>
>>
>> theme(panel.grid.major.x = element_line(size = 0.1, color = "grey"),
>>           panel.grid.major.y = element_blank(),
>>           panel.grid.minor = element_blank()
>>     )
>>
>>
>>
>> Note that if you remove the y axis grid you must set the x axis grid
>> explicitly.
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>> Às 18:52 de 08/01/20, Ana Marija escreveu:
>>> Hello,
>>>
>>> I have this plot in attach. I was wondering how can I change my
>>> plotting code in order to remove these gray horizontal background
>>> lines but keep these two vertical lines? These two vertical lines
>>> don't need to be gray, can be any other type of lines but they must be
>>> at the same place. Also how can I make these two bars narrower?
>>>
>>> library("ggplot2")
>>> p<-ggplot(data=toplot, aes(x=cat, y=props)) +
>>>     geom_bar(stat="identity", fill="steelblue")+
>>>     geom_errorbar(aes(ymin=props-1.96*ses, ymax=props+1.96*ses), width=.2,
>>>                   position=position_dodge(.9))  +
>>>
>>>     geom_signif(comparisons=list( c("All eQTL", "eQTL from 103 genes"),
>>>                                  c("All SNPs", "eQTL from 103 genes")),
>>>                 y_position=c(0.065, 0.07), tip_length=0, annotation=c("p
>>> = 0.0012", "p = 0.0023")) +
>>>     scale_y_continuous(breaks=seq(0,.06,by=.01)) +
>>>     xlab("") + ylab("Proportion p-values < 0.05") +
>>>     theme_minimal()
>>> p
>>>
>>>
>>> ______________________________________________
>>> [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.