legend for group of lines in ggplot - r

I am trying to plot a group of lines and assign one label to these lines in the legend. Here's an example of the data (df2) that I am using.
structure(list(
true = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),
.Label = c("model1", "model2"), class = "factor"),
test = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L),
.Label = c("false.model1", "false.model2", "false.model3", "true model"), class = "factor"),
est.interval = c(0, 5, 5, 7, 7, 10, 10, 11, 11, 0, 2, 2, 3, 3, 0, 2, 2, 4, 4, 0, 2, 2, 3, 3, 4, 4, 0, 7, 7, 10, 10, 13, 13, 0, 4, 4, 5, 5, 0, 5, 5, 6, 6, 7, 7, 9, 9, 0, 2, 2, 3, 3, 4, 4),
sens = c(1, 1, 0.75, 0.75, 0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.25, 0.25, 0, 1, 1, 0.5, 0.5, 0, 1, 1, 0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.75, 0.75, 0.25, 0.25, 0, 1, 1, 0.5, 0.5, 0, 1, 1, 0.75, 0.75, 0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.5, 0.5, 0.25, 0.25, 0)),
.Names = c("true", "test", "est.interval", "sens"),
class = "data.frame")
And here I plot the curves using ggplot.
ggplot(df2, aes(x=est.interval, y=sens, color=test)) +
ylim(0,1) +
geom_line(size = 0.6) +
facet_wrap(~true, nrow=1) +
scale_colour_manual(values=c(rep('#CCCCCC', 3), "#000000"), name="Estimation Model") +
guides(color=guide_legend(keywidth = 3, keyheight = 1))
I'd like to have the three grey "false.model" curves separately visible on the plot, but in the legend I just want one "false models" entry beside one grey line. Any thoughts on how to do this?

I had a problem with your dput. It seemed to be missing rownames which made it an invalid data.frame. Here a corrected dump
df2 <- structure(list(true = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("model1",
"model2"), class = "factor"), test = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 4L, 4L), .Label = c("false.model1", "false.model2", "false.model3",
"true model"), class = "factor"), est.interval = c(0, 5, 5, 7,
7, 10, 10, 11, 11, 0, 2, 2, 3, 3, 0, 2, 2, 4, 4, 0, 2, 2, 3,
3, 4, 4, 0, 7, 7, 10, 10, 13, 13, 0, 4, 4, 5, 5, 0, 5, 5, 6,
6, 7, 7, 9, 9, 0, 2, 2, 3, 3, 4, 4), sens = c(1, 1, 0.75, 0.75,
0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.25, 0.25, 0, 1, 1, 0.5, 0.5,
0, 1, 1, 0.5, 0.5, 0.25, 0.25, 0, 1, 1, 0.75, 0.75, 0.25, 0.25,
0, 1, 1, 0.5, 0.5, 0, 1, 1, 0.75, 0.75, 0.5, 0.5, 0.25, 0.25,
0, 1, 1, 0.5, 0.5, 0.25, 0.25, 0)), .Names = c("true", "test",
"est.interval", "sens"), row.names = c(NA, -54L), class = "data.frame")
The easiest thing to do would be to create a new factor that you can use for the coloring. For example
df2$testcol<-factor(ifelse(df2$test=="true model",1,2),
levels=1:2,
labels=c("True Model","False Model"))
Now all the false models will share a common value. Then you can do
ggplot(df2, aes(x=est.interval, y=sens, group=test, colour=testcol)) +
ylim(0,1) +
geom_line(size = 0.6) +
facet_wrap(~true, nrow=1) +
scale_colour_manual(values=c("True Model"='#CC0000',
"False Model"="#999999"), name="Estimation Model") +
guides(color=guide_legend(keywidth = 3, keyheight = 1))
to get

Related

How to set the color range of scatter plot so it is consistent with histogram

I have the following data set:
dat <- structure(list(
cell_name = structure(c(
1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L
), .Label = c("Px", "Cx", "Mx", "Ox", "OC"), class = "factor"),
gexp = c(
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.078053491967664,
0.0787946080465952, 0.0849179303351091, 0.0893393503333397,
0.0904401481651504, 0.108991747968639, 0.109472235592895,
0.120876521863314, 0.121633996276386, 0.133260178961047,
0.141422491346724, 0.151765761772331, 0.163039227361379,
0.181821496314555, 0.183023962970076, 0.185012779171506,
0.190674320101334, 0.191500130355834, 0.245151812914058,
0.251786197407558, 0.268528061492397, 0.303601828212538,
0.33030785071184, 0.380051212059645, 0.409937261758804, 0.413185421525087
), sample.category = structure(c(
2L, 1L, 1L, 1L, 1L, 1L,
3L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L,
1L, 1L, 3L, 1L, 3L, 2L, 1L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L,
1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 1L, 1L,
1L, 2L, 3L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L,
1L, 3L, 3L, 1L, 3L, 3L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 1L, 1L, 3L,
1L, 2L, 1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L,
2L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 3L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L
), .Label = c(
"Xt.NT.0hr",
"Xt.Saline.16hr", "Xt.Compound.16hr"
), class = "factor"),
x = c(
-6.12836877150557, -7.88484374327681, -6.18700496001265,
-6.45607224745772, -6.91398421568892, -5.17557040495894,
-5.00434676451704, -5.90220013899824, -5.52279416365645,
-7.23571482939741, -4.00645772261641, -7.60095492644331,
-6.57969895644209, -5.71780339522383, -7.29465762419722,
-6.09494725508711, -6.92634764952681, -7.31916800780318,
-7.69346801085493, -4.80783835692427, -5.9156226281645, -6.23338071150801,
-6.39048472685835, -3.98181144042036, -7.35286227507613,
-6.37823573393843, -5.96767512602827, -4.74095240874312,
-7.12100688262007, -7.69579879088423, -7.40592185301802,
-5.54702035231612, -7.33453170104048, -6.12831488890669,
-7.86401644988081, -5.20023671431563, -6.26484719557783,
-7.81010619444868, -6.60071936888716, -7.31798640532515,
-4.35606614394209, -6.38609496397993, -7.18059436125777,
-6.27779713912031, -7.20054999632857, -7.76712313933394,
-5.52495375914595, -6.24379435820601, -5.23566857619307,
-6.05110780043623, -6.87949982924483, -7.27079001708052,
-6.85096398634932, -5.3437461022856, -3.93442956252119, -7.59850207610152,
-7.65125361723921, -6.25943747801802, -7.33143512053511,
-6.33743230147383, -6.08643952651045, -7.55096713347456,
-7.11144343657515, -5.95002309126875, -6.10922948164961,
-7.18890372557661, -7.12671843810103, -6.24059716506026,
-4.30699292464278, -5.66289655013106, -4.80185262007735,
-7.13948622984907, -6.67150870604536, -7.37687579436323,
-7.78391352934859, -7.2490023736479, -5.74496260924361, -6.03136102004073,
-7.06212893767378, -6.37314883513472, -5.33852473540327,
-6.11003104491255, -5.68365517897627, -7.04923526091597,
-5.93282214446089, -6.32528439803145, -4.86897603316328,
-7.29054347319624, -7.63038436217329, -5.71889964385054,
-6.09542743010542, -4.82401458067915, -5.97893325133345,
-6.71384087843916, -7.20524493498823, -4.3980297212126, -4.11487237257979,
-6.85030833525679, -6.87816754622481, -7.87402716918013,
-5.62621775908491, -4.99655858321211, -4.66852847380659,
-7.57268325133345, -5.39896384520552, -6.60474101347945,
-7.77267066283247, -7.69671145720503, -5.77326957030318,
-7.80957309050581, -4.55219546599409, -6.01630631728194,
-5.50212136549971, -7.76106826109907, -4.21713153166792,
-7.63483706755659, -7.89539233489058, -4.19935838027022,
-5.78868190093062, -5.27231732649824, -6.6918529634001, -7.19847861571333,
-6.77350703520796, -7.29259482665083, -7.66503230376265,
-5.92225924773238, -5.94090358061812, -4.94412461562178,
-5.27848092360518, -6.46139279646895, -4.23630992217085,
-6.28692427916548, -5.00668660445235, -5.03211299223921,
-7.29572287840864, -5.33259049696944
), y = c(
-5.02424657839496,
-6.71462500590045, -4.64553797739703, -4.8909190942641, -5.71065485972125,
-4.82234514254291, -5.28217733401019, -3.866351013362, -4.37375534075458,
-6.48378050821979, -1.45741885650117, -5.84999812144, -5.37730658549029,
-5.34863889712054, -5.33161938685138, -4.89835823076923,
-5.95062935847003, -4.7071119596358, -6.26194823282916, -5.22036922472674,
-4.32524025934894, -3.79248035448749, -4.39562714594562,
-5.28746831911761, -4.56550610560138, -5.81744492548663,
-1.6384685088988, -2.85430014628131, -6.03716719645221, -7.30025113123614,
-7.1568714429732, -6.01424372690875, -6.00170434015948, -3.03584480780322,
-6.57955277460773, -4.41522968310077, -5.37504447001178,
-6.52249014872272, -4.75782311457355, -4.62974846857745,
-4.80379808443744, -4.52536237734515, -5.20433223742206,
-4.70545566576678, -6.43369257944781, -6.41709864634235,
-4.82305062311847, -2.91744268435199, -4.4250496675368, -5.37218845385272,
-4.68633187311847, -2.56733632582385, -2.32696414488513,
-2.86756802099902, -5.36454570788104, -6.49232972162921,
-7.18896258372027, -5.87897027033527, -5.03146756190021,
-3.6963902761336, -4.67556036013324, -7.27969754236896, -4.89728296297748,
-4.84503138560016, -3.55614126223285, -2.56781030195911,
-6.00860703486163, -2.6597498704787, -5.33996284502704, -3.27229035395343,
-5.52028096216876, -6.94654047983844, -5.05352461832721,
-4.85841691988666, -6.13735354441363, -2.54840064543445,
-2.09675896662433, -4.46512854593951, -6.61105263727862,
-6.10234320658404, -4.03706944483478, -4.91794002550799,
-2.51595926779468, -4.77913272875506, -2.05771953362186,
-5.00882280367572, -5.52451956766803, -6.13459790247638,
-6.88176024454791, -5.43877637881, -4.64195335406024, -2.93488967913348,
-4.90864980715472, -3.13988101977069, -2.98691988486011,
-2.36754042404849, -1.61479792493541, -2.42353100079257,
-5.22080147761066, -6.9881349851485, -2.50280356901843, -2.4409405042525,
-5.19058645266254, -6.65987217920978, -5.1250020315047, -4.80788171786029,
-6.56144059199054, -7.22644150751788, -5.39587510126788,
-6.68008864420611, -3.0989873458739, -3.61012685793597, -3.17221487063129,
-7.18178618448932, -2.10658872622211, -7.30663311976153,
-7.09194481867511, -1.59743498015363, -2.7611458351012, -5.10656679171283,
-2.5872366477843, -3.18813729780871, -6.07152092951495, -4.62400186556537,
-6.3747350026961, -2.67246747511584, -6.22303259867389, -2.53317165869433,
-2.45842046040256, -3.20620191591937, -1.96011829870898,
-2.98910189169604, -2.67913473147113, -1.90748242038447,
-6.58255875605304, -2.57597566145618
), cluster = c(
1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1
)
), row.names = c(NA, -136L), class = c("tbl_df", "tbl","data.frame"))
I am making the histogram and scatter plot with this code:
library(tidyverse)
library(ggpubr)
## Making Barplot (histogram)
nbp <- ggpubr::ggbarplot(dat, x = "sample.category", y = "gexp", facet.by = "cell_name", add = "mean_se", scales = "fixed") +
theme(strip.text.x = element_text(size = 20, colour = "black", face = "bold")) +
theme(legend.position = "none") +
xlab("") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
nbp
## Making scatter plot (histogram)
pge <- ggplot(dat, aes(x, y, color = gexp)) +
geom_point(alpha = 0.9, size = 5) +
scale_color_gradient(low = "#ededed", high = "#67000d", na.value = "#f0f0f0") +
facet_wrap(cell_name ~ sample.category, scales = "free", ncol = 3) +
theme_bw() +
xlab("UMAP 1") +
ylab("UMAP 2")
pge
The bar plot looks like this:
And scatter plot with color scale looks like this:
As you can see in the histogram clearly Xt.Saline.16hr is stronger
than Xt.NT.0hr. But in the scatter plot color scale we get the vivid
impression that Xt.NT.0hr is stronger than Xt.Saline.16hr.
How can I adjust the color scale in scatter plot so that it
matches the histogram?
I post an answer to be able to show some plots.
As remarked in the comment, your plot seems correct. However, boxplot alone might be misleading in this case.
If you add the actual points you will see that many NT points are equal to 0 and some of them peaks just above 0.4. Please, see the plot below, I have used your color scale and geom_jitter to show distribution of your points for the gexp variable.
library(ggplot2)
ggplot(data = dat, aes(x = sample.category, y = gexp, color = gexp)) +
# geom_boxplot() +
facet_grid(.~sample.category, scale = "free_x") +
geom_jitter() +
scale_color_gradient(low = "#ededed", high = "#67000d", na.value = "#f0f0f0") +
theme_bw()

How to make a stacked barplot with nested grouping variables?

I am trying to make a stacked barplot with two variables. My desired outcome looks like this:
This is the first part of my data. There are 220 more rows:
Type Week Stage
<chr> <dbl> <dbl>
1 Captured 1 2
2 Captured 1 1
3 Captured 1 1
4 Captured 1 2
5 Captured 1 1
6 Captured 1 3
7 Captured 1 NA
8 Captured 1 3
9 Captured 1 2
10 Captured 1 1
So far I'm not getting anywhere, this is my code so far
library(data.table)
dat.m <- melt(newrstudio2, id.vars="Type")
dat.m
library(ggplot2)
ggplot(dat.m, aes(x=Type, y=value, fill=variable)) +
geom_bar(stat="identity")
I guess I need to calculate the number of observations of each stage in each week of each type? I've tried both long and wide data, but I somehow need to combine week with type? I don't know, I'm at a loss.
Alternative way:
set.seed(123)
# sample data
my_data <- data.frame(Type = sample(c("W", "C"), 220, replace = TRUE),
Week = sample(paste0("Week ", 1:4), 220, replace = TRUE),
Stage = sample(paste0('S', 1:4), 220, replace = TRUE))
head(my_data)
library(ggplot2)
ggplot(my_data, aes(x = Type, fill = Stage)) +
geom_bar(aes(y = (..count..)/sum(..count..)), position = "fill") +
facet_grid(. ~ Week, switch="both") +
scale_y_continuous(labels = scales::percent) +
ylab("Stage [%]") +
theme(strip.background = element_blank(),
strip.placement = "outside",
panel.spacing = unit(0, "lines"))
Alternatively we could use base graphics. First, what you're probably most interested in, we should reshape the data.
For this we could split the data per week and run a dcast() over it.
L <- lapply(split(d, d$week), function(x)
data.table::dcast(x, type ~ stage, value.var="stage", fun=length))
d2 <- do.call(rbind, L) # transform back into a data frame
Now – with credits to #alemol – we want the proportions.
d2[-1] <- t(apply(d2[-1], 1, prop.table))
Then we are able to plot relatively simply. Note, that barplot() additionally gives us a vector of bar coordinates which we can use later for the axis() labels.
cols <- c("#ed1c24", "#ff7f27", "#00a2e8", "#fff200") # define stage colors
par(mar=c(5, 5, 3, 5) + .1, xpd=TRUE) # set plot margins
p <- barplot(t(d2[-1]), col=cols, border="white", space=rep(c(.2, 0), 5),
font.axis=2, xaxt="n", yaxt="n", xlab="Week")
axis(1, at=p, labels=rep(c("C", "W"), 5), tick=FALSE, line=0)
axis(1, at=apply(matrix(p, , 2, byrow=TRUE), 1, mean), labels=1:5, tick=FALSE, line=1)
axis(2, at=0:10/10, labels=pa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 3L, 3L, 3L, 2L,
1L, 3L, 4L, 2L, 4L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 2L, 1L, 3L, 2L,
1L, 1L, 1L, 4L, 2L, 4L, 1L, 4L, 3L, 4L, 4L, 4L, 2L, 2L, 2L, 2L,
2L, 1L, 3L, 4L, 2L, 4L, 4L, 2L, 2L, 3L, 4L, 4L, 3L, 3L, 1L, 1L,
1L, 2L, 4L, 3L, 1L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 4L, 2L, 1L,
2L, 1L, 3L, 3L, 2L, 4L, 3L, 1L, 1L, 4L, 1L, 4L, 4L, 1L, 2L, 2L,
2L, 1L, 3L, 4L, 3L, 4L, 3L, 4L, 4L, 3L, 1L, 1L, 2L, 1L, 2L, 3L,
2L, 2L, 1L, 4L, 3L, 4L, 2L, 2L, 3L, 1L, 2L, 3L, 3L, 3L, 3L, 2L,
1L, 2L, 2L, 1L, 1L, 3L, 4L, 3L, 4L, 2L, 4L, 1L, 1L, 2L, 1L, 3L,
2L, 1L, 3L, 3L, 2L, 2L, 1L, 3L, 2L, 2L, 2L, 1L, 4L, 2L, 4L, 2L,
4L, 3L, 3L, 1L, 3L, 4L, 3L, 2L, 1L, 2L, 4L, 1L, 2L, 4L, 2L, 1L,
2L, 1L, 2L, 2L, 3L, 1L, 3L, 3L, 3L, 2L, 2L, 1L, 2L, 3L, 2L, 2L,
1L, 2L, 1L, 3L, 3L, 2L, 1L, 3L, 4L, 2L, 1L, 2L, 4L, 3L, 4L, 2L,
3L, 2L, 4L, 1L, 4L, 4L, 2L, 1L, 2L)), row.names = c(NA, -250L
), class = "data.frame")
Is this what you're looking for:
set.seed(123)
# sample data
my_data <- data.frame(Type = sample(paste0('T', 1:4), 220, replace = TRUE),
Week = sample(paste0('W', 1:4), 220, replace = TRUE),
Stage = sample(paste0('S', 1:4), 220, replace = TRUE))
ggplot(my_data, aes(x=Week:Type, fill = Stage)) + geom_bar()

Trying to run a simple logistic regression without luck

I am trying to run a logistic regression on a small data set, but after going at it for three weeks I am about to give up. I have been getting a range of error messages and I am now even having doubts whether my R engine is working as it should. DPUT of my data looks like this:
structure(list(SEASON = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L
), .Label = c("1", "2", "3"), class = "factor"), OO_OBS = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1,
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1), HW_OBS = c(1, 1, 1, 0,
0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L), .Label = c("0", "NA"), class = "factor"),
INIT_BOTH = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L,
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L), .Label = c("0", "1", "NA"), class = "factor"),
as.is = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE)), .Names = c("SEASON", "OO_OBS", "HW_OBS", "F_OO",
"F_HW", "INIT_OO", "INIT_HW", "INIT_BOTH", "as.is"), row.names = c(NA,
-119L), class = "data.frame")
These variables are all factors with two levels, except SEASON, that has three levels.
I want to run a logistic regression where "F_HW" is the response variable and "SEASON" and "F_OO" are dependent variables. This is the script I have been trying to run, which should be really simple, but it doesn't work (my data object is called feed.df):
feed.df$SEASON <- as.factor(feed.df$SEASON)
feed.df$F_OO <- as.factor(feed.df$F_OO)
feed.df$FEED_HW <- as.factor(feed.df$FEED_HW)
attach(feed.df)
ml <- glm(F_HW ~ SEASON + F_OO, family=binomial)
lm.out = glm(F_HW ~ SEASON + F_OO, family=binomial)
summary (lm.out)

Add a vertical line to a ggplot2, but not to every facet

Suppose I have this data.frame:
my.df <- structure(list(mean = c(0.045729661, 0.030416531, 0.043202944,
0.025600973, 0.040526913, 0.046167044, 0.029352414, 0.021477789,
0.027580529, 0.017614864, 0.020324659, 0.027547972, 0.0268722,
0.030804717, 0.021502093, 0.008342398, 0.02295506, 0.022386184,
0.030849534, 0.017291356, 0.030957321, 0.01871551, 0.016945678,
0.014143042, 0.026686185, 0.020877973, 0.028612298, 0.013227244,
0.010710895, 0.024460647, 0.03704981, 0.019832982, 0.031858501,
0.022194059, 0.030575241, 0.024632496, 0.040815748, 0.025595652,
0.023839083, 0.026474704, 0.033000706, 0.044125751, 0.02714219,
0.025724641, 0.020767752, 0.026480009, 0.016794441, 0.00709195
), std.dev = c(0.007455271, 0.006120299, 0.008243454, 0.005552582,
0.006871527, 0.008920899, 0.007137174, 0.00582671, 0.007439398,
0.005265133, 0.006180637, 0.008312494, 0.006628951, 0.005956211,
0.008532386, 0.00613411, 0.005741645, 0.005876588, 0.006640122,
0.005339993, 0.008842722, 0.006246828, 0.005532832, 0.005594483,
0.007268493, 0.006634795, 0.008287031, 0.00588119, 0.004479003,
0.006333063, 0.00803285, 0.006226441, 0.009681048, 0.006457784,
0.006045368, 0.006293256, 0.008062195, 0.00857954, 0.008160441,
0.006830088, 0.008095485, 0.006665062, 0.007437581, 0.008599525,
0.008242957, 0.006379928, 0.007168385, 0.004643819), parent.origin = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("maternal",
"paternal"), class = "factor"), group = structure(c(4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("F1i:F",
"F1i:M", "F1r:F", "F1r:M"), class = "factor"), replicate = c(1,
2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4,
5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1,
2, 3, 4, 5, 6)), .Names = c("mean", "std.dev", "parent.origin",
"group", "replicate"), row.names = c(NA, -48L), class = "data.frame")
Which I'm plotting this way:
library(ggplot2)
p1 <- ggplot(data = my.df, aes(factor(replicate), color = factor(parent.origin)))
p1 <- p1 + geom_boxplot(aes(fill = factor(parent.origin),lower = mean - std.dev, upper = mean + std.dev, middle = mean, ymin = mean - 3*std.dev, ymax = mean + 3*std.dev), position = position_dodge(width = 0), width = 0.5, alpha = 0.5, stat="identity") + facet_wrap(~group, ncol = 4)+scale_fill_manual(values = c("red","blue"),labels = c("maternal","paternal"),name = "parental allele")+scale_colour_manual(values = c("red","blue"),labels = c("maternal","paternal"),name = "parental allele")
p1 <- p1 + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_rect(fill = 'white', colour = 'white'), legend.position = "none")+theme(strip.background=element_rect(fill="white"))
Which produces:
What I'd like to do is add black vertical lines to the left of the left facet, to the right of the right facet (i.e., left and right y axis lines), and another one between the 2nd and 3rd facets - right in the middle.
I know that geom_vline is the function I should be using but I can only get it to add a line for each facet. But what I want is lines that, at least how I see it, are independent of the facets.
Is this possible?
It is possible. Add the following line:
p1 <- p1 + geom_vline(data=data.frame(x= c(0,7,7), group = levels(my.df$group)[-3]), aes(xintercept = x), size=2 )

Plotting 3-way interaction of factor variables using `lme4`

I'm looking for an elaboration on the amazing answer already provided about creating an interaction plot with a continuous and categorical variable using the predict function of the (development version) of the lme4 package.
I have run a model with an interaction between three categorical variables: discount_i (0/1), rank_i (0/1), and msg ("No norm","Provincial",and "Norm") including subject random effects (id). My outcome variable (choice) is dichotomous. Specifically, my command is:
m1 <- glmer(choice ~ msg*discount_i*rank_i + (1|id), data=df, family="binomial")
I then create a prediction frame:
predframe <- with(df,expand.grid(rank_i=levels(rank_i),msg=levels(msg),discount_i=levels(discount_i)))
And use the predict function (EDITED):
predframe$pred.logit <- predict(m1,newdata=predframe,REform=NA)
However, this is the point where I part ways with #mnel's instructions. How would I go about graphing the three way interaction between factor variables, rather than a two way interaction between a factor variable and a continuous variable?
Sample data below:
> dput(df[1:700,2:6])
structure(list(time = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1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L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L,
2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L,
2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L), .Label = c("0", "1"), class = "factor")), .Names = c("time",
"choice", "msg", "discount_i", "rank_i"), row.names = c("1.1",
"2.1", "3.1", "4.1", "5.1", "6.1", "7.1", "8.1", "9.1", "10.1",
"11.1", "12.1", "13.1", "14.1", "15.1", "16.1", "17.1", "18.1",
"19.1", "20.1", "21.1", "22.1", "23.1", "24.1", "25.1", "26.1",
"27.1", "28.1", "29.1", "30.1", "31.1", "32.1", "33.1", "34.1",
"35.1", "36.1", "37.1", "38.1", "39.1", "40.1", "41.1", "42.1",
"43.1", "44.1", "45.1", "46.1", "47.1", "48.1", "49.1", "50.1",
"51.1", "52.1", "53.1", "54.1", "55.1", "56.1", "57.1", "58.1",
"59.1", "60.1", "61.1", "62.1", "63.1", "64.1", "65.1", "66.1",
"67.1", "68.1", "69.1", "70.1", "71.1", "72.1", "73.1", "74.1",
"75.1", "76.1", "77.1", "78.1", "79.1", "80.1", "81.1", "82.1",
"83.1", "84.1", "85.1", "86.1", "87.1", "88.1", "89.1", "90.1",
"91.1", "92.1", "93.1", "94.1", "95.1", "96.1", "97.1", "98.1",
"99.1", "100.1", "101.1", "102.1", "103.1", "104.1", "105.1",
"106.1", "107.1", "108.1", "109.1", "110.1", "111.1", "112.1",
"113.1", "114.1", "115.1", "116.1", "117.1", "118.1", "119.1",
"120.1", "121.1", "122.1", "123.1", "124.1", "125.1", "126.1",
"127.1", "128.1", "129.1", "130.1", "131.1", "132.1", "133.1",
"134.1", "135.1", "136.1", "137.1", "138.1", "139.1", "140.1",
"141.1", "142.1", "143.1", "144.1", "145.1", "146.1", "147.1",
"148.1", "149.1", "150.1", "151.1", "152.1", "153.1", "154.1",
"155.1", "156.1", "157.1", "158.1", "159.1", "160.1", "161.1",
"162.1", "163.1", "164.1", "165.1", "166.1", "167.1", "168.1",
"169.1", "170.1", "171.1", "172.1", "173.1", "174.1", "175.1",
"176.1", "177.1", "178.1", "179.1", "180.1", "181.1", "182.1",
"183.1", "184.1", "185.1", "186.1", "187.1", "188.1", "189.1",
"190.1", "191.1", "192.1", "193.1", "194.1", "195.1", "196.1",
"197.1", "198.1", "199.1", "200.1", "201.1", "202.1", "203.1",
"204.1", "205.1", "206.1", "207.1", "208.1", "209.1", "210.1",
"211.1", "212.1", "213.1", "214.1", "215.1", "216.1", "217.1",
"218.1", "219.1", "220.1", "221.1", "222.1", "223.1", "224.1",
"225.1", "226.1", "227.1", "228.1", "229.1", "230.1", "231.1",
"232.1", "233.1", "234.1", "235.1", "236.1", "237.1", "238.1",
"239.1", "240.1", "241.1", "242.1", "243.1", "244.1", "245.1",
"246.1", "247.1", "248.1", "249.1", "250.1", "251.1", "252.1",
"253.1", "254.1", "255.1", "256.1", "257.1", "258.1", "259.1",
"260.1", "261.1", "262.1", "263.1", "264.1", "265.1", "266.1",
"267.1", "268.1", "269.1", "270.1", "271.1", "272.1", "273.1",
"274.1", "275.1", "276.1", "277.1", "278.1", "279.1", "280.1",
"281.1", "282.1", "283.1", "284.1", "285.1", "286.1", "287.1",
"288.1", "289.1", "290.1", "291.1", "292.1", "293.1", "294.1",
"295.1", "296.1", "297.1", "298.1", "299.1", "300.1", "301.1",
"302.1", "303.1", "304.1", "305.1", "306.1", "307.1", "308.1",
"309.1", "310.1", "311.1", "312.1", "313.1", "314.1", "315.1",
"316.1", "317.1", "318.1", "319.1", "320.1", "321.1", "322.1",
"323.1", "324.1", "325.1", "326.1", "327.1", "328.1", "329.1",
"330.1", "331.1", "332.1", "333.1", "334.1", "335.1", "336.1",
"337.1", "338.1", "339.1", "340.1", "341.1", "342.1", "343.1",
"344.1", "345.1", "346.1", "347.1", "348.1", "349.1", "350.1",
"351.1", "352.1", "353.1", "354.1", "355.1", "356.1", "357.1",
"358.1", "359.1", "360.1", "361.1", "362.1", "363.1", "364.1",
"365.1", "366.1", "367.1", "368.1", "369.1", "370.1", "371.1",
"372.1", "373.1", "374.1", "375.1", "376.1", "377.1", "378.1",
"379.1", "380.1", "381.1", "382.1", "383.1", "384.1", "385.1",
"386.1", "387.1", "388.1", "389.1", "390.1", "391.1", "392.1",
"393.1", "394.1", "395.1", "396.1", "397.1", "398.1", "399.1",
"400.1", "401.1", "402.1", "403.1", "404.1", "405.1", "406.1",
"407.1", "408.1", "409.1", "410.1", "411.1", "412.1", "413.1",
"414.1", "415.1", "416.1", "417.1", "418.1", "419.1", "420.1",
"421.1", "422.1", "423.1", "424.1", "425.1", "426.1", "427.1",
"428.1", "429.1", "430.1", "431.1", "432.1", "433.1", "434.1",
"435.1", "436.1", "437.1", "438.1", "439.1", "440.1", "441.1",
"442.1", "443.1", "444.1", "445.1", "446.1", "447.1", "448.1",
"449.1", "450.1", "451.1", "452.1", "453.1", "454.1", "455.1",
"456.1", "457.1", "458.1", "459.1", "460.1", "461.1", "462.1",
"463.1", "464.1", "465.1", "466.1", "467.1", "468.1", "469.1",
"470.1", "471.1", "472.1", "473.1", "474.1", "475.1", "476.1",
"477.1", "478.1", "479.1", "480.1", "481.1", "482.1", "483.1",
"484.1", "485.1", "486.1", "487.1", "488.1", "489.1", "490.1",
"491.1", "492.1", "493.1", "494.1", "495.1", "496.1", "497.1",
"498.1", "499.1", "500.1", "501.1", "502.1", "503.1", "504.1",
"505.1", "506.1", "507.1", "508.1", "509.1", "510.1", "511.1",
"512.1", "513.1", "514.1", "515.1", "516.1", "517.1", "518.1",
"519.1", "520.1", "521.1", "522.1", "523.1", "524.1", "525.1",
"526.1", "527.1", "528.1", "529.1", "530.1", "531.1", "532.1",
"533.1", "534.1", "535.1", "536.1", "537.1", "538.1", "539.1",
"540.1", "541.1", "542.1", "543.1", "544.1", "545.1", "546.1",
"547.1", "548.1", "549.1", "550.1", "551.1", "552.1", "553.1",
"554.1", "555.1", "556.1", "557.1", "558.1", "559.1", "560.1",
"561.1", "562.1", "563.1", "564.1", "565.1", "566.1", "567.1",
"568.1", "569.1", "570.1", "571.1", "572.1", "573.1", "574.1",
"575.1", "576.1", "577.1", "578.1", "579.1", "580.1", "581.1",
"582.1", "583.1", "584.1", "585.1", "586.1", "587.1", "588.1",
"589.1", "590.1", "591.1", "592.1", "593.1", "594.1", "595.1",
"596.1", "597.1", "598.1", "599.1", "600.1", "601.1", "602.1",
"603.1", "604.1", "605.1", "606.1", "607.1", "608.1", "609.1",
"610.1", "611.1", "612.1", "613.1", "614.1", "615.1", "616.1",
"617.1", "618.1", "619.1", "620.1", "621.1", "622.1", "623.1",
"624.1", "625.1", "626.1", "627.1", "628.1", "629.1", "630.1",
"631.1", "632.1", "633.1", "634.1", "635.1", "636.1", "637.1",
"638.1", "639.1", "640.1", "641.1", "642.1", "643.1", "644.1",
"645.1", "646.1", "647.1", "648.1", "649.1", "650.1", "651.1",
"652.1", "653.1", "654.1", "655.1", "656.1", "657.1", "658.1",
"659.1", "660.1", "661.1", "662.1", "663.1", "664.1", "665.1",
"666.1", "667.1", "668.1", "669.1", "670.1", "671.1", "672.1",
"673.1", "674.1", "675.1", "676.1", "677.1", "678.1", "679.1",
"680.1", "681.1", "682.1", "683.1", "684.1", "685.1", "686.1",
"687.1", "688.1", "689.1", "690.1", "691.1", "692.1", "693.1",
"694.1", "695.1", "696.1", "697.1", "698.1", "699.1", "700.1"
), class = "data.frame")
Caveat: Have not added the ylab="" to the second overlaid plot call and you probably want to use a non-default ylab for the first one, too. Since the details of this analysis are still opaque to me, I am not standing behind its validity. (Just turning the crank on the machinery.) And there would need to be some further work on the legend. Furthermore, teh ylims were different so would probably want to set them to min and max for c(newpred0, newpred1).
newpred0 <- predict(m1, newdata = predframe[predframe$discount_i=="0", ] ,
REform = NA)
interaction.plot(droplevels(predframe[predframe$discount_i=="0", ])$rank_i,
droplevels(predframe[predframe$discount_i=="0", ])$msg,
newpred0)
newpred1 <- predict(m1, newdata = predframe[predframe$discount_i=="1", ] ,
REform = NA)
par(new=TRUE); # This is the way to overlay base graphics on top of each other
interaction.plot(droplevels(predframe[predframe$discount_i=="1", ])$rank_i,
droplevels(predframe[predframe$discount_i=="1", ])$msg, newpred1,
col="red")

Resources