Ggplot ggstance::position_dodgev not working for lines - r

I am trying to make a line plot but a lot of the lines overlap and I cannot fix that. I found a function that works with the dots but it is not working with the lines.
Here is my data:
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("14",
"15", "18", "19", "20", "21", "22"), class = "factor"), session = c(1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10), item = c("2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"
), score = c(NA, 2L, 2L, 2L, 2L, 2L, 2L, 2L, NA, NA, 4L, 4L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, NA, 1L, 1L, 2L, 3L, 1L, 2L, 1L,
2L, NA, NA, 2L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2L, 2L,
2L, 2L, 2L, NA, NA, NA, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 3L, NA,
NA, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, NA)), row.names = c(NA, -70L
), class = c("tbl_df", "tbl", "data.frame"))
And here is my code for the plot:
ggplot(data = iwi, aes(x = session, y = score, group = id)) +
geom_point(size = 2,aes(colour = id),
position=ggstance::position_dodgev(height=0.3)) +
geom_line(size = 1.2,aes(group = id, colour = id),
position=ggstance::position_dodgev(height=0.3)) +
scale_y_continuous(name = "score",
limits = c(0,4),
breaks = c(0,1,2,3,4))
It looks like this:
You can see how it is messing up with the lines, so instead of joining point 1 to point 2 and so on, it joins point 2 to 1 and then point 3. Here is how the plot looks without using position_dodgev():
As you can see, everyone with a score of 2 gets into a single line which is useless. How can I fix this? position_dodgev() works amazing for the points, only doesn't work with the lines.

Related

ggplot: geom_text does not center-align above geom_col()

Please find my data p below. I had to include 100 samples to reproduce the error.
Question: why is geom_text not printing consistently center-aligned above the geom_col - e.g. 21 and 28 in All in the right SSA-facet? I tried adjusting position.dodge2 and vjust, but that did not work.
This thread addressed the issue but did not solve my problem.
My script
ggplot(p %>%
mutate(nystudie=as.character(study),
best.resp =as.factor(response)) %>%
group_by(nystudie,best.resp) %>%
summarise(N=n(),Val=unique(treatment)) %>%
bind_rows(p %>% filter(response %in% 1:4, treatment!="Control") %>% droplevels() %>%
mutate(nystudie=as.character(study),
best.resp =as.factor(response)) %>%
group_by(best.resp,treatment) %>% summarise(N=n()) %>%
mutate(nystudie="All") %>%
rename(Val=treatment)),
aes(nystudie, N, color = best.resp, fill= best.resp)) +
geom_col(position = position_dodge2(preserve = "single", padding = 0.1)) +
facet_wrap(~Val,ncol = 2, scales="free") +
scale_fill_grey(name="") +
scale_color_grey(name="") +
scale_y_continuous(breaks = seq(0,120,20)) +
geom_text(aes(label=N),position = position_dodge2(.5), vjust=0, fontface=2, cex=4.5, show.legend = F) +
theme(strip.background = element_blank(),
strip.text = element_text(color = "black", size = 15),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
plot.margin = unit(c(1,3,1,1), "lines"))
Data
p <- structure(list(study = structure(c(8L, 12L, 12L, 12L, 4L, 4L,
1L, 11L, 11L, 13L, 1L, 13L, 14L, 9L, 9L, 10L, 12L, 11L, 4L, 11L,
11L, 12L, 8L, 11L, 13L, 11L, 6L, 15L, 6L, 4L, 7L, 13L, 11L, 4L,
1L, 6L, 1L, 11L, 16L, 1L, 10L, 15L, 1L, 11L, 1L, 6L, 1L, 11L,
12L, 11L, 13L, 16L, 1L, 8L, 11L, 10L, 4L, 4L, 12L, 10L, 6L, 15L,
12L, 14L, 12L, 1L, 1L, 16L, 12L, 12L, 8L, 7L, 1L, 1L, 13L, 13L,
14L, 9L, 14L, 2L, 11L, 4L, 1L, 16L, 15L, 11L, 9L, 4L, 13L, 12L,
6L, 16L, 4L, 1L, 15L, 6L, 4L, 1L, 9L, 2L), .Label = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
"15", "22"), class = "factor"), response = c("1", "3", "4", "4",
"3", "3", "3", "4", "4", "4", "4", "4", "3", "4", "4", "4", "3",
"4", "4", "4", "4", "3", "1", "4", "4", "4", "3", "4", "3", "3",
"4", "4", "4", "3", "4", "4", "4", "4", "4", "3", "4", "4", "3",
"4", "4", "3", "3", "4", "3", "4", "4", "4", "4", "3", "3", "4",
"4", "3", "3", "4", "3", "4", "4", "4", "3", "3", "4", "4", "4",
"4", "2", "4", "4", "4", "4", "4", "3", "4", "3", "3", "4", "4",
"4", "4", "4", "4", "3", "3", "4", "4", "3", "4", "4", "4", "4",
"3", "3", "4", "2", "3"), treatment = structure(c(2L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L,
1L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L,
1L), .Label = c("SSTR", "SSA"), class = "factor")), row.names = c(NA,
-100L), class = "data.frame")
When adding labels you have to take care to use the same positioning as for geom_col. To align the labels with the bars use position_dodge2(preserve = "single", width = .9, padding = 0.1):
library(ggplot2)
library(dplyr)
d1 <- p %>%
mutate(
nystudie = as.character(study),
best.resp = as.factor(response)
) %>%
group_by(nystudie, best.resp) %>%
summarise(N = n(), Val = unique(treatment))
#> `summarise()` regrouping output by 'nystudie' (override with `.groups` argument)
d2 <- p %>%
filter(response %in% 1:4, treatment != "Control") %>%
droplevels() %>%
mutate(
nystudie = as.character(study),
best.resp = as.factor(response)
) %>%
group_by(best.resp, treatment) %>%
summarise(N = n()) %>%
mutate(nystudie = "All") %>%
rename(Val = treatment)
#> `summarise()` regrouping output by 'best.resp' (override with `.groups` argument)
d <- bind_rows(d1, d2)
ggplot(d, aes(nystudie, N, color = best.resp, fill = best.resp)) +
geom_col(position = position_dodge2(preserve = "single", padding = 0.1)) +
facet_wrap(~Val, ncol = 2, scales = "free") +
scale_fill_grey(name = "") +
scale_color_grey(name = "") +
scale_y_continuous(breaks = seq(0, 120, 20)) +
geom_text(aes(label = N), position = position_dodge2(preserve = "single", width = .9, padding = 0.1), vjust = 0, fontface = 2, cex = 4.5, show.legend = F) +
theme(
strip.background = element_blank(),
strip.text = element_text(color = "black", size = 15),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
plot.margin = unit(c(1, 3, 1, 1), "lines")
)

Why do the outliers appear at whisker when I add them via geom_jitter with ggplot?

I have the following boxplots:
As you can see, at the fourth boxplot, the outliers appear already at 4 on the y-axis. The whisker goes until 6.
I couldn't really figure out where the problem in my code is. The intention to show the outlier with geom_jitter is because the plot does not give enough information on the actual distribution.
Here is my code and below an excerpt from the data to try
my_xlab <- paste(levels(df$income_class),"\n(N=",table(df$income_class),")",sep="")
df %>%
group_by(income_class) %>%
mutate(outlier = nr_trips > median(nr_trips) + IQR(nr_trips) * 1.5) %>%
ggplot(aes(x=income_class, y=nr_trips)) +
geom_boxplot(varwidth = TRUE, outlier.shape = NA)+
scale_x_discrete(labels=my_xlab)+
stat_summary(fun.data = "mean_cl_normal",
aes(shape="mean"),
size=4,
colour = "red",
geom="point") +
scale_shape_manual("", values=c("mean"="x"))+
theme_minimal() +
geom_jitter(data = function(x) dplyr::filter_(x, ~ outlier), width = 0.25, height = 0, alpha = .1, aes(color = "outlier")) +
scale_color_manual(name = "", values = c("outlier" = "black"))+
labs(x = "Income class", y="Number of AToD trips")+
scale_y_continuous(breaks=c(0,2,4,6,8, 10, 12, 14), limits = c(0, 12))
The data:
structure(list(income_class = c("1", "1", "1", "3", "3", "3",
"3", "2", "3", "2", "4", "1", "2", "3", "2", "3", "2", "2", "3",
"1", "2", "2", "2", "2", "2", "2", "4", "2", "3", "2", "2", "3",
"3", "3", "4", "4", "2", "3", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "1", "3", "3", "2", "2",
"3", "2", "2", "2", "4", "4", "4", "3", "3", "2", "3", "3", "1",
"2", "2", "2", "3", "4", "3", "3", "2", "2", "2", "3", "3", "2",
"3", "3", "1", "1", "4", "4", "2", "2", "4", "4", "2", "2", "2",
"2", "2", "2", "2", "1", "2", "2", "4", "4", "4", "1", "1", "3",
"3", "3", "3", "4", "4", "4", "4", "4", "4", "4", "4", "4", "3",
"4", "4", "4", "4", "4", "4", "4", "2", "3", "3", "3", "3", "2",
"2", "2", "2", "3", "4", "3", "3", "2", "3", "3", "2", "3", "3",
"2", "3", "2", "2", "2", "2", "2", "2", "2", "2", "1", "1", "2",
"4", "4", "3", "3", "3", "3", "1", "2", "4", "4", "2", "2", "2",
"2", "4", "2", "2", "3", "2", "4", "3", "3", "3", "3", "2", "2",
"3", "3", "3", "3", "3", "4", "4", "4", "4", "3", "2", "2", "2",
"3", "2", "2", "2", "4", "4", "4", "3", "1", "3", "3", "2", "2",
"2", "3", "3", "2", "2", "1", "1", "1", "2", "2", "2", "2", "1",
"4", "4", "2", "3", "3", "1", "2", "4", "4", "2", "2", "2", "3",
"3", "2", "2", "3", "3", "3", "1", "4", "4", "4", "1", "1", "3",
"4", "4", "1", "3", "1", "2", "2", "2", "4", "1", "2", "1", "2",
"3", "2", "2", "3", "3", "2", "2", "1", "3", "3", "4", "4", "2",
"2", "2", "3", "2", "3", "2", "4", "4", "2", "2", "2", "1", "1",
"2", "1", "1", "2", "2", "2", "3", "3", "3", "3", "3", "3", "3",
"2", "4", "4", "3", "3", "3", "2", "2", "2", "2", "2", "2", "3",
"4", "2", "2", "2", "3", "3", "4", "4", "1", "2", "3", "4", "1",
"4", "4", "4", "4", "4", "3", "3", "3", "2", "2", "2", "3", "3",
"2", "2", "2", "2", "3", "3", "2", "2", "3", "4", "4", "4", "2",
"2", "3", "3", "2", "2", "2", "3", "3", "4", "4", "4", "1", "2",
"2", "2", "2", "1", "1", "2", "4", "3", "1", "1", "1", "4", "2",
"2", "1", "3", "3", "3", "3", "4", "4", "4", "4", "4", "4", "3",
"3", "3", "3", "3", "3", "2", "4", "3", "4", "4", "2", "3", "3",
"3", "1", "2", "2", "2", "4", "4", "4", "4", "4", "4", "2", "4",
"3", "2", "2", "2", "4", "3", "3", "3", "3", "4", "4", "1", "2",
"1", "4", "4", "4", "1", "1", "4", "3", "3", "4", "4", "1", "1",
"4", "4", "4", "3", "3", "2", "4", "4", "4", "2", "2", "2", "4",
"4", "4", "4", "2", "2", "3", "1", "1", "1", "3", "3", "4", "1",
"2", "3", "2", "4", "2", "2", "4", "3", "3", "3", "3", "3", "4",
"2", "2", "2", "3", "2", "2", "2", "4", "4", "3", "2", "2", "3",
"3", "3", "3", "2", "2", "2", "2", "2", "2", "2", "3", "3", "4",
"4", "4", "4", "4", "4", "4", "2", "4", "4", "2", "4", "4", "1",
"3", "3", "3", "3", "4", "4", "2", "2", "3", "2", "2", "2", "2",
"2", "2", "2", "1", "3", "3", "3", "1", "4", "2", "2", "3", "3",
"3", "4", "4", "3", "3", "2", "2", "1", "1", "2", "4", "4", "4",
"1", "2", "2", "2", "2", "4", "4", "4", "4", "4", "4", "1", "1",
"2", "1", "4", "4", "1", "4", "4", "3", "2", "2", "4", "2", "4",
"4", "4", "4", "2", "2", "4", "4", "4", "1", "1", "1", "2", "3",
"4", "2", "4", "4", "2", "2", "4", "4", "4", "4", "4", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "1", "4", "2", "2",
"2", "3", "3", "3", "3", "3", "2", "2", "2", "2", "4", "4", "3",
"3", "1", "3", "3", "2", "2", "3", "3", "3", "3", "3", "3", "3",
"4", "4", "4", "4", "2", "2", "2", "2", "2", "3", "2", "2", "2",
"2", "2", "4", "4", "1", "4", "4", "3", "3", "3", "3", "2", "2",
"2", "4", "4", "1", "3", "3", "3", "3", "3", "4", "1", "3", "3",
"1", "1", "4", "3", "3", "4", "4", "4", "1", "2", "2", "2", "3",
"3", "4", "3", "3", "2", "2", "2", "2", "2", "4", "4", "2", "3",
"3", "2", "3", "3", "1", "2", "3", "3", "3", "4", "4", "4", "4",
"2", "3", "3", "3", "3", "2", "2", "3", "3", "3", "3", "2", "2",
"3", "4", "4", "3", "3", "2", "2", "3", "3", "3", "3", "3", "3",
"3", "3", "3", "3", "3", "2", "2", "3", "3", "3", "2", "2", "2",
"2", "1", "1", "2", "4", "4", "2", "2", "3", "3", "3", "1", "3",
"3", "2", "2", "2", "2", "2", "3", "4", "3", "3", "3", "4", "3",
"1", "2", "2", "2", "2", "2", "4", "1", "2", "1", "2", "3", "3",
"2", "1", "3", "2", "4", "2", "2", "2", "2", "2", "1", "3", "3",
"3", "2", "1", "1", "3", "1", "1", "2", "2", "2", "2", "2", "4",
"4", "1", "2", "3", "2", "2", "2", "2", "3", "3", "2", "3", "3",
"4", "4", "3", "3", "3", "4", "3", "3", "3", "2", "4", "4", "1",
"2", "2", "2", "2", "2", "1", "3", "3", "3", "2", "2", "2", "4",
"4", "3", "4", "3", "2", "2", "3", "2", "2", "4", "4", "4", "4",
"4", "4", "4", "3", "3", "3", "2", "2", "4", "4", "2", "3", "2",
"2", "2", "2", "3", "3", "4", "4", "4", "2", "2", "3", "2", "3",
"3", "3", "3", "2", "4", "3", "3", "3", "3", "3", "3", "4", "2",
"2", "2", "4", "4", "2", "3", "3", "2", "4", "2", "4", "2", "3",
"3", "2", "3", "3", "4", "2", "1", "1", "2", "2", "4", "4", "1",
"1", "2", "1", "3", "3", "3", "2", "2", "2", "4", "4", "2", "3",
"3", "2", "2", "3", "3", "2", "2", "4", "2", "2", "3", "4", "3",
"3", "3", "2", "4", "4", "4", "4", "2", "2", "2", "3", "2", "2",
"3", "3", "4", "4", "4", "4", "2", "2", "2", "2", "3", "2", "2",
"4", "4", "4", "3", "4", "4", "3", "2", "2", "2", "3", "4", "3",
"3", "3", "3", "1", "2", "4", "2", "4", "4", "4", "3", "3", "2",
"2", "4", "4", "4", "3", "3", "2", "2", "3", "2", "2", "3", "3",
"1", "2", "1", "1", "4", "2", "2", "4", "2", "3", "2", "2", "2",
"3", "3", "3", "3", "4", "4", "4", "2", "1", "2", "2", "2", "3",
"2", "2", "2", "2", "4", "4", "4", "4", "3", "3", "2", "2", "2",
"2", "2", "2", "4", "2", "2", "4", "2", "2", "2", "2", "3", "2",
"2", "3", "2", "2", "2", "2", "2", "2", "2", "2", "3", "1", "1",
"1", "3", "2", "4", "4", "4", "4", "2", "2", "4", "4", "2", "2",
"2", "2", "1", "4", "4", "2", "3", "2", "3", "4", "2", "2", "1",
"1", "2", "2", "3", "3", "4", "3", "3", "1", "3", "3", "4", "4",
"2", "3", "3", "1", "4", "2", "2", "3", "2", "1", "3", "3", "1",
"2", "2", "4", "2", "2", "2", "2", "2", "4", "4", "4", "2", "4",
"2", "3", "3", "2", "3", "3", "3", "1", "4", "3", "3", "3", "3",
"1", "3", "3", "4", "4", "2", "2", "2", "2", "2", "2", "3", "4",
"3", "3", "1", "3", "2", "2", "2", "2", "3", "3", "3", "1", "2",
"2", "2", "2", "2", "2", "3", "3", "4", "4", "1", "4", "2", "2",
"2", "2", "2", "2", "2", "1", "3", "2", "2", "4", "4", "4", "4",
"3", "3", "1", "1", "1", "4", "4", "4", "2", "3", "3", "3", "1",
"3", "3", "3", "3", "3", "2", "3", "3", "3", "3", "4", "4", "4",
"2", "2", "2", "1", "2", "2", "2", "4", "4", "2", "2", "2", "2",
"3", "3", "3", "3", "3", "2", "4", "4", "4", "4", "1", "1", "2",
"2", "4", "4", "4", "3", "3", "3", "3", "4", "4", "4", "2", "1",
"4", "4", "4", "4", "1", "4", "4", "4", "4", "4", "2", "3", "3",
"3", "3", "3", "4", "4", "4", "1", "1", "4", "2", "3", "3", "2",
"3", "3", "1", "4", "4", "4", "4", "1", "4", "4", "4", "4", "2",
"2", "3", "3", "4", "4", "1", "3", "3", "2", "1", "4", "1", "2",
"4", "4", "4", "4", "2", "4", "2", "3", "2", "2", "2", "4", "4",
"1", "1", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3",
"3", "3", "4", "1", "1", "3", "2", "2", "4", "4", "4", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "4", "4", "4", "4", "2",
"2", "2", "2", "4", "4", "2", "2", "2", "4", "4", "4", "3", "3",
"3", "3", "3", "3", "3", "3", "3", "2", "2", "2", "2", "2", "3",
"3", "2", "2", "2", "3", "3", "4", "3", "3", "3", "3", "2", "2",
"2", "3", "3", "4", "3", "2", "2", "4", "2", "3", "3", "3", "3",
"1", "4", "2", "2", "2", "2", "2", "4", "4", "1", "4", "3", "2",
"4", "4", "4", "4", "4", "4", "3", "3", "4", "4", "4", "4", "2",
"1", "2", "4", "4", "2", "2", "2", "2", "1", "1", "4", "3", "1",
"3", "3", "1", "2", "2", "2", "2", "3", "2", "2", "3", "3", "2",
"3", "3", "2", "4", "2", "2", "2", "2", "3", "2", "2", "1", "1",
"1", "2", "2", "2", "4", "2", "2", "3", "3", "2", "2", "4", "1",
"2", "2", "2", "2", "1", "1", "2", "2", "2", "1", "2", "3", "3",
"2", "2", "2", "3", "4", "3", "3", "1", "2", "2", "1", "1", "4",
"2", "2", "1", "1", "2", "3", "2", "2", "2", "1", "4", "4", "4",
"3", "1", "1", "3", "3", "4", "2", "2", "2", "2", "3", "3", "4",
"4", "3", "2", "2", "2", "2", "4", "4", "4", "3", "3", "3", "3",
"3", "3", "3", "2", "3", "3", "2", "2", "3", "3", "3", "3", "3",
"3", "3", "3", "4", "2", "4", "4", "2", "2", "2", "3", "3", "3",
"3", "3", "4", "2", "4", "4", "3", "3", "3", "4", "3", "2", "2",
"3", "3", "3", "2", "2", "2", "2", "3", "3", "2", "2", "1", "1",
"4", "3", "2", "2", "2", "4", "4", "2", "2", "2", "2", "4", "4",
"4", "2", "4", "3", "1", "3", "3", "2", "3", "1", "2", "4", "3",
"2", "2", "3", "3", "3", "2", "3", "3", "1", "2", "3", "2", "2",
"2", "2", "2", "4", "4", "4", "2", "4", "4", "3", "3", "3", "3",
"3", "2", "2", "3", "3", "3", "4", "3", "3", "3", "3", "2", "2",
"3", "3", "3", "3", "3", "3", "2", "4", "3", "3", "3", "4", "4",
"4", "2", "2", "2", "1", "2", "2", "3", "3", "2", "4", "3", "3",
"3", "1", "3", "2", "2", "3", "3", "3", "4", "3", "3", "1", "4",
"4", "4", "4", "2", "2", "2", "4", "2", "2", "3", "3", "3", "3",
"3", "3", "4", "4", "3", "3", "3", "2", "4", "2", "2", "1", "3",
"4", "4", "2", "2", "1", "2", "3", "3", "3", "2", "2", "2", "4",
"4", "3", "3", "4", "4", "2", "1", "3", "3", "3", "2", "3", "3",
"3", "1", "2", "2", "4", "2", "2", "2", "2", "2", "2", "2", "4",
"2", "2", "3", "3", "3", "3", "3", "2", "2", "3", "3", "3", "2",
"2", "3", "3", "3", "1", "4", "2", "3", "3", "3", "4", "2", "4",
"3", "3", "3", "3", "3", "2", "2", "2", "4", "3", "3", "3", "3",
"1", "4", "2", "2", "2", "3", "3", "3", "3", "3", "3", "3", "2",
"2", "2", "2", "2", "4", "1", "3", "2", "4", "4", "2", "2", "2",
"2", "2", "4", "2", "2", "2", "2", "2", "1", "2", "2", "3", "3",
"3", "3", "3", "3", "3", "2", "4", "4", "3", "3", "4", "4", "3",
"2", "3", "3", "2", "3", "2", "3", "2", "3", "3", "3", "3", "3",
"3", "3", "3", "2", "3", "2", "3", "3", "2", "2", "2", "1", "1",
"3", "2", "4", "4", "1", "3", "3", "2", "2", "3", "2", "2", "2",
"2", "3", "4", "4", "2", "4", "4", "3", "3", "3", "2", "2", "4",
"3", "3", "3", "3", "1", "1", "2", "1", "3", "3", "4", "4", "4",
"4", "3", "3", "3", "4", "4", "4", "2", "2", "3", "3", "2", "3",
"4", "4", "2", "2", "2", "4", "4", "4", "2", "1", "4", "3", "3",
"3", "2", "2", "2", "2", "4", "4", "3", "3", "3", "3", "2", "3",
"2", "2", "2", "1", "4", "4", "3", "3", "3", "3", "3", "2", "3",
"3", "4", "4", "4", "4", "1", "1", "3", "2", "1", "2", "2", "2",
"2", "2", "2", "4", "3", "2", "2", "2", "3", "2", "2", "2", "3",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "1", "2", "2",
"3", "3", "2", "1", "3", "2", "2", "2", "2", "2", "2", "2", "3",
"2", "2", "3", "3", "3", "2", "1", "2", "3", "3", "3", "3", "2",
"2", "2", "2", "4", "4", "4", "2", "3", "3", "4", "3", "3", "2",
"3", "3", "4", "4", "1", "1", "2", "2", "3", "3", "2", "4", "3",
"3", "3", "2", "2", "2", "2", "1", "3", "3", "2", "2", "2", "2",
"4", "4", "2", "2", "2", "2", "4", "4", "4", "1", "2", "4", "3",
"3", "3", "1", "1", "3", "2", "2", "2", "3", "3", "2", "2", "2",
"2", "3", "3", "3", "3", "3", "2", "2", "2", "4", "2", "2", "3",
"3", "3", "3", "4", "2", "2", "3", "4", "4", "4", "4", "2", "2",
"2", "3", "2", "3", "3", "2", "3", "3", "3", "2", "4", "2", "2",
"2", "2", "2", "2", "3", "4", "4", "3", "1", "2", "1", "2", "3",
"2", "2", "2", "1", "2", "2", "2", "2", "2", "2", "4", "4", "1",
"3", "2", "3", "2", "2", "2", "1", "2", "3", "3", "4", "1", "2",
"1", "2", "2", "2", "3", "2", "2", "2", "3", "1", "3", "2", "2",
"4", "4", "1", "3", "2", "3", "1", "1", "1", "2", "2", "3", "3",
"4", "1", "2", "2", "1", "4", "4", "4", "2", "1", "3", "3", "1",
"3", "2", "2", "1", "2", "2", "2", "2", "2", "2", "2", "2", "3",
"3", "3", "1", "3", "2", "2", "4", "3", "1", "2", "3", "3", "3",
"2", "3", "1", "4", "4", "2", "3", "3", "2", "4", "3", "2", "2",
"3", "2", "3", "3", "2", "2", "3", "3", "3", "4", "2", "2", "1",
"2", "1", "2", "4", "1", "1", "2", "2", "2", "2", "2", "4", "1",
"3", "2", "2", "3", "3", "3", "2", "2", "3", "2", "2", "4", "1",
"1", "3", "3", "2", "2", "2", "2", "3", "2", "1", "1", "1", "2",
"2", "2", "2", "4", "4", "2", "3", "3", "4", "4", "2", "2", "3",
"2", "2", "2", "2", "4", "1", "2", "1", "1", "3", "2", "2", "1",
"2", "2", "2", "1", "2", "2", "1", "2", "2", "2", "2", "2", "1",
"2", "2", "2", "1", "1", "2", "2", "1", "1", "1", "2", "1", "1",
"1", "2", "1", "2", "3", "3", "4", "4", "4", "4", "3", "4", "1",
"3", "3", "3", "2", "2", "2", "2", "2", "3", "3", "2", "3", "3",
"3", "3", "2", "2", "4", "1", "2", "3", "3", "3", "2", "4", "4",
"4", "4", "3", "3", "2", "2", "4", "1", "1", "2", "2", "3", "1",
"3", "3", "2", "2", "2", "3", "3", "3", "3", "3", "3", "3", "3",
"2", "2", "4", "4", "3", "3", "3", "4", "4", "4", "4", "3", "4",
"3", "3", "4", "4", "3", "3", "3", "3", "3", "4", "4", "1", "1",
"1", "4", "2", "4", "4", "4", "2", "2", "2", "3", "3", "3", "2",
"2", "2", "4", "4", "4", "2", "2", "2", "2", "2", "1", "2", "4",
"2", "3", "3", "3", "3", "4", "4", "3", "3", "2", "2", "4", "4",
"4", "4", "4", "1", "1", "1", "1", "2", "2", "2", "2", "3", "3",
"3", "2", "2", "3", "3", "4", "4", "2", "2", "2", "2", "2", "2",
"4", "4", "2", "2", "1", "1", "1", "1", "2", "2", "2", "3", "4",
"4", "4", "4", "4", "4", "4", "2", "2", "4", "4", "4", "3", "1",
"1", "2", "2", "2", "2", "1", "4", "4", "2", "2", "2", "3", "3",
"3", "3", "2", "3", "3", "4", "4", "4", "3", "3", "3", "3", "3",
"3", "3", "3", "3", "2", "2", "2", "3", "3", "3", "4", "4", "4",
"4", "3", "2", "4", "3", "2", "2", "3", "1", "3", "3", "1", "4",
"4", "2", "3", "3", "2", "2", "1", "2", "4", "4", "4", "4", "3",
"4", "2", "2", "2", "4", "4", "4", "4", "4", "4", "2", "2", "2",
"2", "2", "3", "3", "3", "2", "3", "3", "2", "3", "3", "2", "3",
"1", "2", "2", "4", "1", "2", "2", "2", "4", "4", "4", "3", "3",
"3", "3", "3", "4", "4", "4", "4", "4", "3", "3", "3", "3", "1",
"1", "3", "3", "3", "3", "2", "4", "4", "3", "2", "1", "1", "4",
"4", "4", "1", "3", "2", "4", "4", "4", "4", "4", "4", "3", "4",
"3", "3", "3", "3", "3", "2", "2", "2", "2", "2", "2", "3", "4",
"4", "4", "4", "4", "4", "3", "3", "1", "4", "4", "2", "2", "3",
"3", "4", "4", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3",
"3", "3", "3", "3", "2", "2", "4", "3", "3", "3", "3", "4", "3",
"4", "4", "4", "4", "4", "3", "3", "3", "2", "1", "4", "4", "4",
"4", "3", "3", "3", "3", "3", "3", "2", "2", "1", "1", "3", "3",
"3", "3", "4", "1", "1", "2", "4", "4", "1", "2", "2", "2", "2",
"2", "3", "3", "3", "3", "2", "2", "2", "2", "1", "1", "2", "3",
"1", "1", "4", "1", "4", "2", "2", "2", "2", "2", "2", "2", "3",
"2", "4", "4", "4", "4", "1", "4", "2", "2", "2", "4", "3", "3",
"4", "3", "3", "4", "4", "4", "3", "2", "2", "2", "4", "4", "4",
"1", "2", "2", "1", "1", "3", "3", "2", "2", "2", "2", "4", "4",
"1", "2", "4", "4", "2", "2", "3", "3", "2", "2", "2", "2", "1",
"2", "2", "2", "2", "2", "2", "1", "4", "2", "2", "2", "2", "2",
"2", "2", "3", "3", "2", "2", "2", "2", "2", "2", "1", "2", "2",
"2", "3", "2", "3", "1", "4", "4", "3", "3", "3", "3", "3", "3",
"3", "2", "2", "2", "3", "3", "2", "3", "3", "3", "1", "1", "1",
"1", "2", "4", "2", "2", "1", "2", "4", "3", "3", "4", "4", "4",
"4", "4", "4", "2", "2", "1", "1", "2", "3", "2", "1", "1", "3",
"3", "4", "4", "4"), nr_trips = c(0L, 0L, 1L, 1L, 0L, 0L, 2L,
2L, 0L, 3L, 0L, 1L, 0L, 1L, 1L, 1L, 2L, 2L, 0L, 2L, 5L, 4L, 3L,
0L, 2L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 3L,
2L, 2L, 3L, 0L, 2L, 4L, 6L, 1L, 2L, 2L, 2L, 2L, 0L, 0L, 5L, 2L,
6L, 1L, 1L, 1L, 0L, 2L, 7L, 2L, 3L, 2L, 2L, 3L, 1L, 2L, 3L, 2L,
0L, 1L, 1L, 3L, 3L, 3L, 2L, 2L, 2L, 0L, 1L, 4L, 3L, 3L, 0L, 2L,
2L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 3L, 2L, 2L, 1L, 2L, 3L, 2L, 6L,
3L, 3L, 1L, 2L, 2L, 2L, 0L, 1L, 4L, 2L, 2L, 0L, 1L, 2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L, 3L, 2L,
3L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 5L, 2L,
2L, 2L, 2L, 2L, 0L, 1L, 3L, 2L, 3L, 2L, 1L, 4L, 1L, 2L, 1L, 2L,
4L, 1L, 1L, 1L, 2L, 0L, 1L, 0L, 0L, 1L, 2L, 1L, 0L, 4L, 1L, 3L,
2L, 1L, 0L, 1L, 2L, 2L, 0L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 2L, 3L,
2L)), row.names = c(NA, 3000L), class = "data.frame")
The reason you are getting this behavior is because the whisker extends beyond median + 1.5 * IQR. From help("geom_boxplot"):
The lower and upper hinges correspond to the first and third quartiles (the 25th and 75th percentiles). This differs slightly from the method used by the boxplot() function...
The upper whisker extends from the hinge to the largest value no further than 1.5 * IQR from the hinge (where IQR is the inter-quartile range, or distance between the first and third quartiles).
A slight change to your mutate call will fix this issue:
df %>%
group_by(income_class) %>%
mutate(outlier = nr_trips > quantile(nr_trips,0.75) + IQR(nr_trips) * 1.5) %>%
ggplot(aes(x=income_class, y=nr_trips)) +
geom_boxplot(varwidth = TRUE, outlier.shape = NA)+
scale_x_discrete(labels=my_xlab)+
stat_summary(fun.data = "mean_cl_normal",
aes(shape="mean"),
size=4,
colour = "red",
geom="point") +
scale_shape_manual("", values=c("mean"="x"))+
theme_minimal() +
geom_jitter(data = function(x) dplyr::filter_(x, ~ outlier), width = 0.25, height = 0, alpha = .1, aes(color = "outlier")) +
scale_color_manual(name = "", values = c("outlier" = "black"))+
labs(x = "Income class", y="Number of AToD trips")+
scale_y_continuous(breaks=c(0,2,4,6,8, 10, 12, 14), limits = c(0, 12))

mlogit: multinominal probit model with intercept returns error

I am experiencing a problem fitting a multinominal probit with the package mlogit.
I am interested in a model with a single alternative specific covariate with a generic coefficient (more details on notation here). In brief, 2001 respondents are faced with 6 choices. Each respondent possesses a utility score associated with each option. The distribution of choices comes from real data but, for the purpose of this exercise, the utility scores (in a 0 to 100 scale) have been randomly generated to avoid multicollinearity. Since the choice scenario was real, a model with intercept is estimated.
Full data is available here, and the code to transform the data to long format is available here. Below I provide a head of the original data which I subsequently converted into a long format.
#preparing sample data
library(mlogit)
data_head<-head(original_data) ##from https://pastebin.com/28XpX7A4
DT_head_long <- mlogit.data(data_head, shape="wide", varying=1:6, choice="choice_with_6_alternative")
DT_head_long<-structure(list(choice_with_6_alternative = c(FALSE, FALSE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE), alt = 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), random_utility = c(18, 25,
12, 13, 2, 37, 3, 21, 38, 3, 6, 51, 8, 33, 32, 9, 6, 29, 43,
6, 5, 25, 15, 17, 24, 11, 12, 29, 33, 13, 16, 22, 12, 5, 21,
3), chid = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L)), reshapeLong = list(varying = structure(list(
random_utility = c("random_utility.1", "random_utility.2",
"random_utility.3", "random_utility.4", "random_utility.5",
"random_utility.6")), v.names = "random_utility", times = c(1,
2, 3, 4, 5, 6)), v.names = "random_utility", idvar = "chid",
timevar = "alt"), row.names = c("1.1", "1.2", "1.3", "1.4",
"1.5", "1.6", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.1",
"3.2", "3.3", "3.4", "3.5", "3.6", "4.1", "4.2", "4.3", "4.4",
"4.5", "4.6", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6", "6.1",
"6.2", "6.3", "6.4", "6.5", "6.6"), class = c("mlogit.data",
"data.frame"), index = structure(list(chid = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 6L), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor"),
alt = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L,
5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L,
2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c("1",
"2", "3", "4", "5", "6"), class = "factor")), class = "data.frame", row.names = c("1.1",
"1.2", "1.3", "1.4", "1.5", "1.6", "2.1", "2.2", "2.3", "2.4",
"2.5", "2.6", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "4.1",
"4.2", "4.3", "4.4", "4.5", "4.6", "5.1", "5.2", "5.3", "5.4",
"5.5", "5.6", "6.1", "6.2", "6.3", "6.4", "6.5", "6.6")), choice = "choice_with_6_alternative")
#fitting the model with probit=TRUE
probit <- mlogit(choice_with_6_alternative ~ random_utility,
data=DT_head_long,
probit=TRUE)
//The model returns the error:
Error in if (is.null(initial.value) || lnl <= initial.value) break :
missing value where TRUE/FALSE needed
#fitting the model with probit=FALSE
//model without intercept: runs well
probit <- mlogit(choice_with_6_alternative ~ random_utility|0,
data=DT_head_long,
probit=FALSE)
//model with intercept: runs well
logit <- mlogit(choice_with_6_alternative ~ random_utility,
data=DT_head_long,
probit=FALSE)
#my questions:
1- To what the error is related?
2- Is the model non-identified?

Imbricated axis in ggplot

I want to plot under two X,Y axis
The first one would have X axis Timecode and Y as the cumul of each line as line =1 across Timecode
The biggest axis is Y as S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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, 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, 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, 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
), .Label = c("17:03:13", "17:05:44", "17:08:44", "17:11:39",
"17:14:39", "17:18:06", "17:21:13", "17:24:02", "17:27:05", "17:32:43",
"17:35:59", "17:38:40", "17:41:26", "17:44:43", "17:48:14", "17:51:14",
"17:55:00", "17:57:16", "18:00:12", "18:03:16", "18:06:03", "18:09:59",
"18:12:49", "18:15:37", "18:18:01", "18:21:31", "18:26:09", "18:27:58",
"18:29:52", "18:33:21", "18:36:40", "18:38:50", "18:41:25", "18:44:35",
"18:48:45", "18:52:08", "18:54:19", "18:59:52", "19:02:28", "19:06:04",
"19:11:18", "19:15:03", "19:18:06", "19:21:37"), class = "factor"),
Direction = 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, 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), Timecode = structure(c(1545667346,
1545667367, 1545667368, 1545667369, 1545667370, 1545667379,
1545667382, 1545667383, 1545667387, 1545667390, 1545667391,
1545667482, 1545667482, 1545667483, 1545667483, 1545667483,
1545667483, 1545667483, 1545667483, 1545667484, 1545667484,
1545667484, 1545667484, 1545667484, 1545667484, 1545667484,
1545667484, 1545667484, 1545667484, 1545667484, 1545667484,
1545667484, 1545667484, 1545667485, 1545667485, 1545667485,
1545667485, 1545667485, 1545667485, 1545667485, 1545667485,
1545667485, 1545667485, 1545667485, 1545667485, 1545667485,
1545667485, 1545667486, 1545667486, 1545667486, 1545667486,
1545667486, 1545667486, 1545667486, 1545667486, 1545667486,
1545667486, 1545667486, 1545667487, 1545667487, 1545667487,
1545667487, 1545667487, 1545667487, 1545667487, 1545667487,
1545667487, 1545667487, 1545667487, 1545667487, 1545667487,
1545667487, 1545667488, 1545667488, 1545667488, 1545667488,
1545667488, 1545667488, 1545667488, 1545667488, 1545667488,
1545667489, 1545667489, 1545667489, 1545667489, 1545667489,
1545667489, 1545667489, 1545667490, 1545667490, 1545667490,
1545667490, 1545667491, 1545667491, 1545667491, 1545667491,
1545667491, 1545667491, 1545667491, 1545667492, 1545667492,
1545667493, 1545667493, 1545667493, 1545667494, 1545667494,
1545667494, 1545667494, 1545667495, 1545667495, 1545667496,
1545667497, 1545667497, 1545667498, 1545667498, 1545667498,
1545667498, 1545667499, 1545667499, 1545667500, 1545667500,
1545667501, 1545667501, 1545667501, 1545667502, 1545667503,
1545667503, 1545667503, 1545667504, 1545667504, 1545667504,
1545667504, 1545667505, 1545667505, 1545667505, 1545667505,
1545667505, 1545667506, 1545667506, 1545667506, 1545667507,
1545667507, 1545667507, 1545667508, 1545667508, 1545667509,
1545667509, 1545667509, 1545667509, 1545667510, 1545667510,
1545667510, 1545667510, 1545667510, 1545667511, 1545667511,
1545667511, 1545667512, 1545667512, 1545667512, 1545667513,
1545667513, 1545667514, 1545667514, 1545667514, 1545667515,
1545667515, 1545667516, 1545667516, 1545667516, 1545667516,
1545667517, 1545667517, 1545667517, 1545667518, 1545667518,
1545667518, 1545667519, 1545667520, 1545667520, 1545667521,
1545667521, 1545667522, 1545667522, 1545667522, 1545667522,
1545667522, 1545667523, 1545667523, 1545667523, 1545667523,
1545667523, 1545667524, 1545667524, 1545667524, 1545667524,
1545667524, 1545667525, 1545667525, 1545667526), class = c("POSIXct",
"POSIXt"), tzone = ""), Type = c("14", "1", "6", "14", "4",
"6", "14", "6", "4", "1", "6", "5", "6", "1", "8", "5", "4",
"7", "2", "2", "6", "5", "16", "8", "3", "5", "1", "1", "8",
"7", "9", "6", "11", "7", "5", "4", "9", "6", "5", "2", "1",
"12", "4", "4", "14", "14", "12", "7", "1", "6", "3", "4",
"5", "2", "12", "4", "5", "2", "9", "1", "14", "7", "1",
"4", "12", "5", "7", "14", "3", "5", "2", "9", "14", "4",
"6", "1", "2", "5", "4", "3", "9", "3", "1", "9", "4", "4",
"3", "1", "4", "4", "7", "1", "3", "4", "7", "1", "6", "4",
"4", "14", "14", "4", "4", "4", "14", "4", "4", "4", "4",
"6", "4", "1", "4", "7", "6", "7", "14", "7", "6", "7", "4",
"6", "4", "7", "6", "4", "7", "4", "7", "7", "1", "7", "6",
"14", "7", "4", "4", "6", "6", "7", "4", "4", "6", "7", "4",
"7", "4", "7", "4", "6", "7", "4", "4", "1", "6", "4", "4",
"6", "4", "4", "6", "4", "14", "6", "6", "6", "7", "4", "6",
"7", "4", "7", "4", "6", "14", "6", "1", "6", "7", "6", "6",
"4", "6", "6", "7", "7", "6", "7", "7", "6", "4", "1", "7",
"7", "14", "6", "7", "7", "6", "7"), Duration = c(0, 0, 0,
23, 0, 11, 13, 4, 17, 23, 8, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2,
1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 2, 1, 1, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 1, 0, 0, 0, 2,
1, 2, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 2, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 3, 1, 2, 1, 1, 1, 3,
0, 0, 4, 0, 2, 0, 0, 2, 1, 0, 0, 1, 4, 1, 6, 1, 7, 3, 0,
4, 1, 1, 1, 3, 2, 1, 1, 1, 2, 2, 0, 1, 0, 7, 0, 3, 7, 1,
2, 0, 1, 0, 1, 2, 0, 1, 2, 1, 1, 1, 0, 0, 3, 1, 1, 0, 6,
1, 1, 0, 1, 1, 0, 1, 1, 9, 1, 0, 1, 5, 3, 1, 1, 0, 1, 1,
1, 4, 1, 8, 1, 3, 1, 1, 4, 1, 0, 2, 0, 0, 1, 0, 1, 2, 5,
1, 0, 6, 1, 0, 1, 1, 1)), .Names = c("Sample_ID", "Sample_Hour",
"Direction", "Timecode", "Type", "Duration"), row.names = c(NA,
-200L), class = c("tbl_df", "tbl", "data.frame"))
dplyr-approach
first, create a table with an increasing 1 per group (=cumsum of observations/persons)
result <- df %>%
group_by( Sample_ID, Type ) %>%
mutate( nb = 1:n() )
then create a facetted lins/point plot.
The free_x in the facet_grid keeps the result readable. You have to set the axis-labels/breaks manually
ggplot( data = result, aes( x = Timecode, y = nb ) ) +
geom_line( aes( group = 1 ), size = 1 ) +
geom_point() +
facet_grid( Type ~ Sample_ID, scales = "free_x" ) +
scale_x_datetime( date_breaks = "10 secs", labels = date_format( "%H:%M:%S", tz = "" ) ) +
theme(axis.text.x = element_text( angle = 90, vjust = 0.5, hjust = 1 ) )

Visualization of Groups of Poisson random samples using ggridges

I have two sets of data, all in one data frame. The first set is related to data collected in Location 1 and the second set is collected in Location 2. Each location has different count data (column value) for 5 months.
# DataSet
-----------------
rp_data <- structure(list(Month = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("1",
"2", "3", "4", "5"), class = "factor"), location = 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", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2",
"2", "2", "2", "2", "2", "2", "2"), value = c(0L, 1L, 1L, 1L,
2L, 1L, 0L, 0L, 1L, 1L, 3L, 2L, 1L, 4L, 1L, 3L, 1L, 1L, 1L, 1L,
2L, 2L, 1L, 0L, 2L, 4L, 3L, 5L, 5L, 0L, 4L, 3L, 3L, 4L, 2L, 5L,
2L, 3L, 10L, 6L, 5L, 6L, 4L, 6L, 4L, 5L, 6L, 5L, 3L, 7L, 1L,
1L, 1L, 1L, 0L, 0L, 2L, 1L, 2L, 0L, 2L, 3L, 4L, 1L, 2L, 1L, 2L,
0L, 2L, 2L, 4L, 4L, 5L, 1L, 4L, 5L, 4L, 5L, 1L, 4L, 3L, 7L, 7L,
4L, 2L, 5L, 4L, 1L, 5L, 3L, 7L, 3L, 4L, 8L, 5L, 7L, 1L, 1L, 6L,
3L)), .Names = c("Month", "location", "value"), row.names = c(NA,
-100L), class = "data.frame")
I used this example below, as illustrated on the ggridges examples webpage, to display the various count values across different months.
# Plot 1 , filtering data related to location = 1
#---------------
ggplot(rp_data[rp_data$location == '1',], aes(x = value, y = Month, group = Month)) +
geom_density_ridges2(aes(fill = Month), stat = "binline", binwidth = 1, scale = 0.95) +
geom_text(stat = "bin",
aes(y = group + 0.95*(..count../max(..count..)),
label = ifelse(..count..>0, ..count.., "")),
vjust = 1.4, size = 3, color = "white", binwidth = 1) +
scale_x_continuous(breaks = c(0:12), limits = c(-.5, 13), expand = c(0, 0),
name = "random value") +
scale_y_discrete(expand = c(0.01, 0), name = "Month",
labels = c("5.0", "4.0", "3.0", "2.0", "1.0")) +
scale_fill_cyclical(values = c("#0000B0", "#7070D0")) +
labs(title = "Poisson random samples location 1 different Month",
subtitle = "sample size n=10") +
guides(y = "none") +
theme_ridges(grid = FALSE) +
theme(axis.title.x = element_text(hjust = 0.5),
axis.title.y = element_text(hjust = 0.5))
# Plot 2 , filtering data related to location = 2
#---------------
ggplot(rp_data[rp_data$location == '2',], aes(x = value, y = Month, group = Month)) +
geom_density_ridges2(aes(fill = Month), stat = "binline", binwidth = 1, scale = 0.95) +
geom_text(stat = "bin",
aes(y = group + 0.95*(..count../max(..count..)),
label = ifelse(..count..>0, ..count.., "")),
vjust = 1.4, size = 3, color = "white", binwidth = 1) +
scale_x_continuous(breaks = c(0:12), limits = c(-.5, 13), expand = c(0, 0),
name = "random value") +
scale_y_discrete(expand = c(0.01, 0), name = "Month",
labels = c("5.0", "4.0", "3.0", "2.0", "1.0")) +
scale_fill_cyclical(values = c("#0000B0", "#7070D0")) +
labs(title = "Poisson random samples location 2 different Month",
subtitle = "sample size n=10") +
guides(y = "none") +
theme_ridges(grid = FALSE) +
theme(axis.title.x = element_text(hjust = 0.5),
axis.title.y = element_text(hjust = 0.5))
Result for plot 1:
My question is how can I combine these two plots, sort of like an overlay plot as shown in this example:
I don't want to plot them in two separate plots.
You need to create a grouping variable that contains both Month and location. You can do that by using paste0(Month, location). For now, I'm leaving out the text labels, though they may be possible with a little more thought as well. (But I think they'd make the figure too busy.)
ggplot(rp_data,
aes(x = value, y = Month,
group = paste0(Month, location),
fill = paste0(Month, location))) +
geom_density_ridges2(stat = "binline", binwidth = 1,
scale = 0.95, alpha = 0.7) +
scale_x_continuous(breaks = c(0:12), limits = c(-.5, 13),
expand = c(0, 0), name = "random value") +
scale_y_discrete(expand = c(0.01, 0), name = "Month",
labels = c("5.0", "4.0", "3.0", "2.0", "1.0")) +
scale_fill_cyclical(values = c("#0000B0", "#B00000",
"#7070D0", "#FC5E5E")) +
labs(title = "Poisson random samples location 1 different Month",
subtitle = "sample size n=10") +
guides(y = "none") +
theme_ridges(grid = FALSE, center = TRUE)
Edit: Now with text labels.
ggplot(rp_data, aes(x = value, y = Month, group = paste0(Month, location), fill = paste0(Month, location))) +
geom_density_ridges2(stat = "binline", binwidth = 1, scale = 0.95, alpha = 0.7) +
geom_text(stat = "bin",
aes(y = ceiling(group/2) + 0.95*(..count../max(..count..)),
label = ifelse(..count..>0, ..count.., ""), color = location),
vjust = 1.4, size = 3, binwidth = 1, fontface = "bold") +
scale_x_continuous(breaks = c(0:12), limits = c(-.5, 13), expand = c(0, 0),
name = "random value") +
scale_y_discrete(expand = c(0.01, 0), name = "Month",
labels = c("5.0", "4.0", "3.0", "2.0", "1.0")) +
scale_fill_cyclical(values = c("#0000B0", "#B00000", "#7070D0", "#FC5E5E")) +
scale_color_cyclical(values = c("white", "black")) +
labs(title = "Poisson random samples location 1 different Month",
subtitle = "sample size n=10") +
guides(y = "none") +
theme_ridges(grid = FALSE, center = TRUE)
Again, not sure it's a good idea, but there you go.

Resources