--
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+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
Dear Winston,
A while ago I have replied to your helpful
reply via my yahoo account but obviously you did not receive it. Therefore, I'm
now replying via the Google group below:
Dear Winston,
Thanks for your fast reply and for your help.
I apologise for my late reply. I see. This means I can only centre data within
one group but I cannot group the dots of 4 groups and then centre them. What I
was looking for would have been a combination of “# grouping on x and g,
dodging” and “# Stacking groups, using histodot, along y axis”, the last two
examples on “https://github.com/wch/ggplot2/wiki/geom_dotplot”. After trying
various methods, such as ordering my data in different ways, I came to the
conclusion that centring vertical and dodging data is not possible when there
is more than one break on the x-axis (e.g. A, B, and C from the example in
github). Please correct me if I’m wrong. Below I have pasted in the original graph,
the graph using geom_point, and the graph using geom_dodge into this message including the code for the graph using geom_dodge. This is the
best compromise I achieved, but I would be grateful for any suggestions.
In the new version of ggplot2 several
behaviours of the legends are quite odd. I fixed most of them; however, I would
prefer to have the two legends aligned on the left, as in A.plot13. (One way to
do this would be to change the width of legend.background for each legend or to
position each legend separately, but I have no idea how to do this.) Also, I
would like to move the two legends closer together, i.e. the gap between the
legend above and below should be smaller. But after investing quite a lot of
time into these and other R problems I realised that for an R beginner like me
this is not doable. If anyone could help me improve this graph I would be very
grateful. Below I have pasted in the code of the graph where I highlighted the
legend background in red. Ideally, I would like to be able to move the two
legends separately.
I have also pasted in a graph where I
marked the border of the legends in red and one illustrating where I would like
to place them.
Best wishes,
Martin
Figure 1:
A.plot13:
A.plot18:
A.plot18.red_frames:
A.plot18.aim:
R code:
rm(list=ls())
library(proto)
library(grid)
library(plyr)
library(reshape)
library(digest)
library(ggplot2)
library(tools)
setwd("C:\\Users\\mhk\\Documents\\nur.fueR\\ggsave\\")
df.perc.3 <- structure(list(trt = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L,
ggplot() +
geom_line(data = df.perc.2a, aes(y = resp, x = trt, group = group, linetype = group), stat = "identity",
size = 0.5, colour = "black") +
geom_smooth(data = df.perc.2b, aes(y = resp, x = trt, group = group, linetype = group, ymax = resp + se,
ymin = resp - se), stat = "identity", size = 0.5, colour = "black") +
geom_dotplot(data = na.omit(df.perc.3), aes(y = resp, x = factor(trt), fill = group, colour = group, width = 0.4),
position = "dodge", binaxis = "y", stackdir = "center", dotsize = 1, binwidth = 0.5) +
scale_fill_manual(values = c("white", "grey82", "black", "grey40")) +
scale_colour_manual(values = rep("black", 4)) +
scale_x_discrete(expand = c(0, 0.2), name = "age range of eggs (day)") +
scale_y_continuous(expand = c(0.02, 0), breaks = seq(80, 100, 5), name = "eggs remaining (%)") +
theme(legend.position = c(0.6, 0.29), legend.background = element_blank(),
legend.key = element_blank(), legend.key.size = unit(c(0.9, 0.9), "lines"),
legend.title = element_blank(), legend.text = element_text(size = 9)) +
theme(panel.grid.major = element_line(colour = "white", size = 0.5),
axis.text.x = element_text(size = 9, vjust = 0.9),
axis.text.y = element_text(size = 9, hjust = 0.9),
axis.title.x = element_text(size = 11, vjust = 0.61, hjust = 0.6),
axis.title.y = element_text(size = 11, hjust = 0.555, vjust = 0.59, angle = 90),
plot.margin = unit(c(0.3, 0.3, -0.03, -0.23), "lines")) +
guides(group = guide_legend(order = 2), fill = guide_legend(order = 1), colour = guide_legend(order = 1))
ggsave("A.plot18.pdf", width = 85/25.4, height = 85/25.4, family = "sans")
# legend.background highlighted in red:
ggplot() +
geom_line(data = df.perc.2a, aes(y = resp, x = trt, group = group, linetype = group), stat = "identity",
size = 0.5, colour = "black") +
geom_smooth(data = df.perc.2b, aes(y = resp, x = trt, group = group, linetype = group, ymax = resp + se,
ymin = resp - se), stat = "identity", size = 0.5, colour = "black") +
geom_dotplot(data = na.omit(df.perc.3), aes(y = resp, x = factor(trt), fill = group, colour = group, width = 0.4),
position = "dodge", binaxis = "y", stackdir = "center", dotsize = 1, binwidth = 0.5) +
scale_fill_manual(values = c("white", "grey82", "black", "grey40")) +
scale_colour_manual(values = rep("black", 4)) +
scale_x_discrete(expand = c(0, 0.2), name = "age range of eggs (day)") +
scale_y_continuous(expand = c(0.02, 0), breaks = seq(80, 100, 5), name = "eggs remaining (%)") +
theme(legend.position = c(0.6, 0.29), legend.background = element_rect(colour = "red"),
legend.key = element_blank(), legend.key.size = unit(c(0.9, 0.9), "lines"),
legend.title = element_blank(), legend.text = element_text(size = 9)) +
theme(panel.grid.major = element_line(colour = "white", size = 0.5),
axis.text.x = element_text(size = 9, vjust = 0.9),
axis.text.y = element_text(size = 9, hjust = 0.9),
axis.title.x = element_text(size = 11, vjust = 0.61, hjust = 0.6),
axis.title.y = element_text(size = 11, hjust = 0.555, vjust = 0.59, angle = 90),
plot.margin = unit(c(0.3, 0.3, -0.03, -0.23), "lines")) +
guides(group = guide_legend(order = 2), fill = guide_legend(order = 1), colour = guide_legend(order = 1))
ggsave("A.plot18.red_frames.pdf", width = 85/25.4, height = 85/25.4, family = "sans")