Position_dodge not working

60 views
Skip to first unread message

Andrew Tamalunas

unread,
Mar 18, 2017, 7:07:15 AM3/18/17
to ggplot2

I am having trouble getting position_dodge to work to add space between the bars. I have not been able to get any solution I've found online to work after a long time searching and a lot of troubleshooting.


Here is the code I have now, although the first few lines are probably the only relevant ones:


plot3 <- ggplot(PTX, aes(x=Group, y=Percent.Baseline, group = Group)) +
  stat_summary
(fun.data="mean_cl_normal", geom = "errorbar", width = 0.3, size = 1.15) +
  stat_summary
(fun.y="mean", geom="bar",fill = "white", color = "black", size = 2, width = .7) +
  geom_point
(data = PTX, name = "Estrous Cycle", aes(shape = Estrous.Cycle, color = Estrous.Cycle),
             alpha
= 1, size = 10, stroke = 2.7, show.legend=TRUE) +
  scale_shape_manual
(name = "Estrous Cycle",
                     values
=c(0, 1, 2),
                     labels
=c("Proestrous", "Estrous", "Diestrous")) +
  scale_x_discrete
(limits=c("HC", "ES", "IS")) +
  scale_y_continuous
(breaks=c(40,60,80,100,120)) +
  coord_cartesian
(ylim=c(43.8,120)) +
  scale_colour_manual
(name = "Estrous Cycle",
                      labels
= c("Proestrous", "Estrous", "Diestrous"),
                      values
= c("navyblue", "darkgreen", "darkred")) +  
  theme
(panel.border = element_blank(),
        legend
.key = element_rect(fill = NA, colour = NA, size = 0.25),
        axis
.line = element_line(size = 2.5, linetype = "solid",
                                 colour
= "black"),
        panel
.background = element_rect(fill = "transparent", color="NA"),
        axis
.text.x = element_text(colour="grey20",size=24,hjust=.5,vjust=.5,face="bold"),
        axis
.text.y = element_text(colour="grey20",size=24,hjust=1,vjust=0,face="bold"),  
        axis
.title.x=element_blank(),
        axis
.title.y=element_text(face="bold", size=40, color = "black"),
        axis
.ticks.y = element_blank(),
        legend
.key.height=unit(3.2, "line"),
        legend
.key.width=unit(3.2, "line"),
        legend
.title=element_text(size=21),
        legend
.text=element_text(size=21))

plotfinal
<- plot3 + ylab("% Baseline")
plotfinal

Here is the current graph

Hadley Wickham

unread,
Mar 22, 2017, 10:07:36 AM3/22/17
to Andrew Tamalunas, ggplot2
You are more likely to receive help if your provide a minimal reproducible example. Start by using the reprex package to produce a reprex that others can easily run, then reduce your code as much as possible to illustrate the key problem. You can remove 90% of the code you've included in your email because it's not actually relevant to the problem that you describe.

Hadley

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages