Related
I am trying to make a boxplot with the correlation coefficient and their CI values in a boxplot in R. However when I try to add the following line of code it does not work nor gives it a error code.
boxplot(AI~Q8,
data=df6,
main="The relation between Q8 and the A",
xlab="A",
ylab="B",
col="orange",
border="brown",
stat_cor()
)
or
boxplot(AI~Q8,
data=df6,
main="The relation between Q8 and the A",
xlab="A",
ylab="B",
col="orange",
border="brown",
) + stat_cor()
And is it also possible to get a different color for each boxplot?
This is the dataset I use
structure(list(AI = c(0.659967433444017, 0.941802575478176, 0.565824387077681,
0.733813835498287, 0.502486567259441, 0.581214986043292, 0.190601573198807,
0.61511194322592, 0.630316833066587, 0.513634604352834, 0.691766098799664,
0.443331648025045, 0.475498746385683, 0.253183014637901, 0.685340877692643,
1.07517098753888, 1.10219598244924, 0.469261733415629, 0.473732071653954,
1.11472099520751, 1.12140547685593, 0.844644528419478, 0.741480217894283,
0.664326042816726, 0.798610418245564, 0.184662871961999, 0.718894350907626,
0.773529667226157, 0.65593386028412, 0.958431317152659, 0.638301596431948,
0.844678953483002, 1.12048871720509, 1.21583405287684, 0.642731559824528,
0.720376072993178, 0.53551579775883, 0.612011376983417, 0.281431655977777,
1.25176573918925, 1.15328375538737, 1.20957695840318, 1.09278028083012,
0.859636858723266, 1.20869790596587, 1.12288309438874, 0.891306451574103,
0.552552119084953, 0.995259412720299, 1.17674596084747), Q8 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 2L, 2L, 2L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 33L, 34L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L,
52L), class = "data.frame")
You can add correlation in a legend, colors may be specified as vectors.
clr <- hcl.colors(length(unique(df6$Q8)), alpha=.5)
blr <- hcl.colors(length(unique(df6$Q8)), alpha=1)
boxplot(AI ~ Q8,data=df6, main="The relation between Q8 and the A",
xlab="A", ylab="B", col=clr, border=blr)
corr <- with(df6, cor.test(AI, Q8))[c('estimate', 'conf.int')]
legend('topleft',
legend=bquote(rho ==.(signif(corr[[1]], 2))~'['*.(signif(corr[[2]][1], 2))*','~.(signif(corr[[2]][2], 2))*']'),
bty='n')
I am trying to run a code that would enable me to make a comparison between the current versus the past (last 6 months) socioeconomic situation and the voting preference in the last Spanish General Elections, which were in 2019.
If I run this code, I get the correct graphical output for all the parties that participated in the aforementioned elections:
#Analysis of Question 3 (current versus past situation of Spanish consumers, their perception of their own situation) in addition to Question 31a (facet of the respondents' voting preference)
library(ggplot2)
library(dplyr)
set.seed(123)
CIS_data_6 <- data.frame(
CIS$RECUERDO,
CIS$P3
)
dput(CIS_data_6)
CIS_data_6$CIS.P3 <- sub("\\(NO LEER\\) ", "", CIS_data_6$CIS.P3)
labs <- c("Mejor", "Igual", "N.C.", "N.S.", "Peor")
CIS_data_6$CIS.P3 <- factor(CIS_data_6$CIS.P3, labels = labs)
Recuerdo <- CIS_data_6$CIS.RECUERDO
Recuerdolabs <- c("N.P.", "PSOE", "PP", "VOX", "Unidas Podemos", "Ciudadanos")
cut_points <- c(0, 2, 1, 18, c(21, 6, 67), 4)
i <-c(Recuerdo, !is.na(cut_points))
Recuerdo_fac <- Recuerdolabs[i]
Recuerdo_fac[is.na(Recuerdo)] <- Recuerdolabs[length(Recuerdolabs)]
Recuerdo_fac <- factor(Recuerdo_fac, levels = Recuerdolabs)
CIS_data_6$CIS.RECUERDO <- Recuerdo
ggplot(CIS_data_6, aes(Recuerdo)) +
geom_bar() +
xlab("Current VS Past Individual Situation Based on Voting Preference") +
ylab("Count") +
coord_flip() +
facet_wrap(~ CIS.P3) +
theme_bw()
However, this is graphically a mess, since there is all kind of minor parties which are of no relevance to my analysis.
The ones that I do want to outline are the big ones (plus abstention): "N.P." (Abstention), "PSOE", "PP", "VOX", "Unidas Podemos" and "Ciudadanos", with their corresponding encoding in the survey, which I denoted as cut_points: c(0, 2, 1, 18, c(21, 6, 67), 4).
Does anyone know how can I modify my code so that I can get to the desired output, i.e., to have a faceted graph (5 graphs, to be precise) saying "Mejor" ('Better'), "Peor" ('Worse'), "Igual" ('Same'), "N.S." ('Don't Know'), "N.C." ('Don't Answer') on the x-axis in each graph, and the political parties being located on the y-axis?
Many, many thanks in advance!
P.S. I am relatively new to this forum, so please, in case I have not expressed myself correctly or if there is any information lacking in my question, just let me know so, and I will be happy to provide it.
EDIT
dput(CIS_data_6)
is, as follows:
structure(list(CIS.RECUERDO = structure(c(2L, 2L, 28L, 1L, 2L,
1L, 15L, 15L, 2L, 26L, NA, 28L, 28L, 26L, 2L, NA, 13L, 2L, 27L,
2L, 15L, 1L, 27L, NA, 2L, 1L, NA, 1L, 2L, 15L, 25L, 26L, 26L,
26L, 2L, 1L, 15L, 15L, 24L, 1L, 15L, 28L, 2L, 2L, 24L, 3L, NA,
1L, NA, 27L, 1L, 27L, 26L, 2L, 2L, 28L, NA, 15L, 24L, 23L, 27L,
23L, 28L, 1L, 23L, 3L, 1L, 21L, 26L, 27L, 2L, 2L, 3L, 2L, 1L,
2L, 2L, 28L, 28L, 28L, 1L, 15L, 15L, 1L, 1L, 26L, 23L, 2L, 2L,
15L, 15L, 2L, 28L, 28L, 2L, 1L, 1L, 25L, 28L, 28L, 26L, 23L,
1L, 28L, 27L, 1L, 28L, 15L, 2L, 3L, 27L, 1L, 1L, 1L, 15L, 1L,
2L, 1L, 1L, 28L, 28L, 15L, 13L, 1L, 1L, 2L, 3L, 3L, 15L, 3L,
1L, 1L, 28L, 1L, 23L, 26L, 1L, 2L, 1L, 2L, 1L, 27L, 27L, NA,
28L, 26L, 21L, 3L, 28L, 2L, 26L, 2L, 26L, 1L, 26L, 2L, 15L, 3L,
2L, 1L, 15L, 1L, 2L, 2L, 28L, 2L, 28L, 15L, 1L, 2L, 2L, 15L,
NA, 28L, 1L, 1L, 28L, 28L, 15L, 28L, 1L, 1L, 26L, 28L, 2L, 2L,
26L, 28L, 1L, 28L, 3L, 1L, 13L, 26L, 15L, 28L, 1L, 1L, 1L, 2L,
2L, 1L, 1L, 1L, 28L, 26L, 1L, 28L, 28L, 28L, 27L, 23L, 13L, 2L,
27L, 2L, 26L, 2L, 15L, 28L, 1L, 2L, 2L, 24L, 2L, 26L, 2L, 27L,
1L, 28L, 15L, 15L, 13L, 21L, 28L, 13L, NA, 27L, 1L, 23L, 2L,
28L, 1L, 28L, 2L, 15L, 1L, 1L, 28L, 1L, 27L, 24L, 1L, 26L, 26L,
13L, 1L, 26L, 26L, 15L, 28L, 2L, 1L, 15L, 24L, 1L, 28L, 28L,
1L, 3L, 1L, 2L, 15L, 23L, 25L, 28L, 26L, 1L, 27L, 1L, 28L, 1L,
13L, 15L, 23L, 1L, 1L, 28L, 1L, 25L, 2L, 1L, 2L, 26L, 2L, NA,
26L, 25L, 25L, 2L, 2L, 28L, 13L, 15L, 23L, 26L, 2L, 1L, 24L,
2L, 1L, 1L, NA, 28L, 2L, 15L, 2L, 1L, 2L, 1L, 2L, 24L, 28L, 1L,
15L, 2L, 28L, 25L, 1L, 2L, 1L, 27L, 15L, 28L, 2L, 28L, 23L, 22L,
1L, NA, 3L, 2L, 28L, NA, 21L, 1L, 26L, 26L, 2L, 1L, 27L, 1L,
2L, 1L, 26L, 1L, 26L, 24L, 1L, 13L, 26L, 28L, 26L, 26L, 2L, 24L,
27L, 3L, 1L, 2L, 28L, 28L, 27L, 26L, 27L, 23L, 26L, 15L, 2L,
2L, 15L, 27L, 1L, 2L, 1L, 26L, 28L, 3L, 2L, 2L, 1L, 26L, 2L,
2L, 3L, 2L, 2L, 26L, 1L, 2L, 2L, 2L, 3L, 23L, 1L, 3L, 26L, 23L,
15L, 1L, 28L, 2L, 15L, 23L, 26L, 1L, 13L, 15L, 2L, 26L, 2L, 26L,
15L, 2L, 25L, 1L, 26L, 3L, 26L, 2L, 2L, 2L, 3L, 15L, 15L, 28L,
26L, 2L, 3L, 15L, 22L, 2L, 13L, 1L, 1L, 13L, 1L, 2L, 28L, 13L,
26L, 2L, 27L, 2L, 2L, 27L, 3L, 1L, 26L, 28L, 27L, 2L, 1L, 1L,
23L, 26L, 28L, 1L, 2L, 24L, 1L, 28L, 27L, 24L, 1L, 2L, 25L, 1L,
13L, 1L, 26L, 13L, NA, 3L, 28L, 15L, 1L, 15L, 15L, 2L, 28L, 2L,
2L, 2L, 26L, 3L, 25L, 3L, 2L, 1L, 28L, 25L, 26L, 2L, 28L, 27L,
1L, 2L, 24L, 27L, 23L, 2L, 13L, 2L, 27L, 13L, 13L, 2L, 1L, 1L,
25L, 13L, 28L, 22L, 2L, 23L, 28L, 27L, NA, 28L, 2L, 2L, 13L,
2L, 2L, 28L, 2L, 22L, 26L, 2L, NA, 28L, 2L, 2L, 28L, 13L, 2L,
27L, 28L, 3L, 2L, 2L, 24L, 15L, 2L, 23L, 2L, 1L, NA, 1L, 15L,
2L, 28L, 2L, 2L, 2L, 26L, 1L, 1L, 26L, 26L, 15L, 2L, 26L, 2L,
28L, 3L, 27L, 13L, 24L, 13L, 2L, 1L, 2L, 2L, 1L, 25L, 23L, 2L,
26L, 24L, 15L, 15L, 2L, 28L, 26L, 2L, 26L, 2L, 26L, 27L, 28L,
15L, 3L, 2L, 13L, 21L, 15L, 2L, 2L, 1L, NA, 26L, 1L, 2L, NA,
26L, 28L, 1L, 28L, 3L, 2L, 13L, 28L, 15L, 25L, 2L, 13L, 2L, 1L,
13L, 2L, 2L, 2L, 24L, 26L, NA, 2L, 28L, 28L, 1L, 15L, NA, 22L,
26L, 28L, 26L, 28L, 26L, 1L, 2L, 2L, 13L, 2L, 2L, 1L, 2L, 28L,
28L, 3L, 27L, 1L, 1L, NA, 26L, 28L, 2L, 2L, 2L, 2L, 15L, 26L,
3L, 28L, 25L, 28L, 15L, 1L, 26L, 2L, 28L, 26L, 1L, 15L, 26L,
1L, 8L, NA, 2L, 2L, 13L, 28L, 27L, 1L, 23L, 2L, 28L, 24L, 2L,
2L, 28L, 2L, 2L, 28L, 1L, NA, NA, 26L, 3L, 3L, 24L, 28L, 28L,
28L, 27L, 2L, 2L, 2L, 1L, 24L, 15L, 27L, 1L, 1L, 2L, 26L, 28L,
28L, 26L, 1L, 15L, 15L, NA, 2L, 15L, 27L, 28L, 2L, 26L, 24L,
28L, 26L, 23L, 26L, 1L, 26L, 23L, 26L, 2L, 27L, 13L, 28L, 27L,
24L, 26L, 26L, 27L, 26L, 26L, 15L, 2L, 13L, 2L, 3L, 15L, 1L,
1L, 1L, 2L, 2L, 26L, 26L, 2L, 2L, NA, 24L, 15L, 26L, 24L, 27L,
28L, 2L, 2L, 2L, 24L, 27L, 2L, 2L, 28L, 26L, 26L, 26L, 23L, 1L,
2L, 28L, 24L, NA, 13L, 2L, 26L, 3L, 25L, 1L, NA, 3L, 26L, 1L,
25L, 2L, 28L, 26L, 2L, 13L, 2L, 1L, 15L, 26L, 15L, 2L, 2L, 1L,
2L, 15L, 2L, 3L, 23L, 2L, 1L, 28L, 1L, 23L, 28L, 28L, 2L, 1L,
NA, 2L, 1L, 15L, 1L, 2L, 24L, 2L, 2L, 1L, NA, 25L, 3L, 2L, 26L,
13L, 2L, 28L, 1L, 13L, 1L, 27L, 15L, 2L, 25L, 2L, 1L, 1L, 28L,
28L, 26L, 21L, 27L, 26L, 1L, 1L, 3L, NA, 28L, 15L, 28L, 2L, 1L,
2L, 2L, 28L, 2L, 15L, 2L, 27L, 13L, 2L, 13L, 2L, 21L, 13L, 2L,
13L, 2L, 2L, 26L, 28L, 24L, 24L, 2L, 24L, 28L, 13L, 15L, 1L,
2L, 15L, NA, 2L, 27L, 15L, 15L, 1L, 2L, 2L, 2L, 28L, 26L, 1L,
27L, 1L, 28L, 26L, 2L, 1L, 1L, 23L, 24L, 15L, 2L, 1L, 28L, 25L,
28L, 27L, 28L, 1L, 15L, 21L, 27L, 1L, 2L, 1L, 28L, 28L, 24L,
1L, 2L, 2L, 23L, 28L, 23L, 28L, 2L, 2L, NA, 2L, 26L, 26L, 2L,
1L, 1L, 2L, 27L, 2L, 1L, 28L, 2L, 28L, 26L, 28L, NA, 13L, 2L,
2L, NA, 28L, 1L, 3L, 13L, 13L, 2L, 2L, 21L, 15L, 15L, 1L, 28L,
2L, 1L, 13L, 2L, 2L, 26L, 26L, 24L, 3L, 28L, 3L, 15L, 2L, 22L,
27L, 26L, 26L, 1L, 28L, 2L, 28L, 2L, 28L, 2L, 1L, 1L, 1L, 28L,
2L, 15L, 2L, 2L, 2L, NA, 27L, 1L, 2L, 22L, 1L, 27L, 2L, 13L,
1L, 2L, 2L, NA, 3L, 26L, 1L, 2L, 2L, 2L, 26L, 15L, 27L, 28L,
15L, 3L, 28L, 28L, 15L, 26L, NA, 2L, 28L, 28L, 26L, 26L, 2L,
28L, 13L, 28L, 25L, 2L, 27L, 2L, 1L, 13L, 26L, 28L, 26L, 2L,
15L, 26L, 1L, 26L, 26L, 1L, 13L, 1L, 13L, 1L, 26L, 15L, 26L,
1L, 2L, 2L, 2L, 28L, 3L, 28L, 2L, 26L, 13L, 2L, 23L, 2L, 3L,
15L, NA, 2L, NA, 26L, 6L, 2L, 3L, 3L, 2L, 3L, 28L, 27L, 21L,
4L, 6L, 1L, 22L, 28L, 27L, 26L, 4L, 28L, 27L, NA, 26L, 6L, 6L,
2L, 6L, 28L, 7L, 2L, 26L, 27L, NA, 2L, 26L, 2L, 26L, 28L, 4L,
2L, 27L, 6L, 3L, 24L, 27L, 2L, 2L, NA, 23L, 28L, 3L, 27L, 1L,
2L, 27L, 26L, 24L, NA, 27L, 2L, 4L, 4L, 2L, 2L, 24L, 27L, NA,
2L, 2L, NA, 26L, 4L, 6L, NA, 28L, 26L, 4L, 4L, 3L, 24L, 23L,
7L, 2L, 25L, 27L, 2L, 4L, 28L, NA, 2L, 6L, 2L, 2L, 2L, 13L, 6L,
26L, 2L, 2L, 24L, 2L, NA, 28L, 2L, 6L, 1L, 4L, 4L, 3L, 2L, 27L,
2L, NA, 2L, 2L, 7L, 2L, 7L, 28L, NA, 2L, 2L, 27L, 2L, 2L, NA,
3L, 2L, 26L, 27L, 2L, 6L, 1L, 2L, NA, 6L, 26L, 24L, 4L, 4L, 4L,
28L, 4L, 4L, 4L, 4L, 13L, 7L, 26L, 28L, 27L, 6L, NA, NA, 28L,
6L, 26L, 2L, 4L, 24L, 26L, 2L, 1L, 21L, 28L, 7L, 27L, 26L, 28L,
2L, 27L, 26L, 2L, 4L, 26L, 2L, 1L, 27L, 26L, 7L, 28L, 26L, 28L,
27L, 3L, NA, 27L, 28L, 4L, 2L, 4L, 26L, 2L, 7L, 26L, 1L, 2L,
1L, 2L, 6L, 26L, 2L, 2L, 7L, 4L, 26L, 2L, 27L, 2L, 27L, 26L,
27L, 6L, 2L, 26L, 13L, 6L, 2L, 23L, 23L, 4L, 26L, 28L, 3L, 28L,
22L, 26L, 1L, 6L, 26L, 27L, 6L, 27L, 2L, 6L, 21L, 4L, 6L, 28L,
28L, 4L, 4L, 2L, 28L, 2L, 21L, 2L, 2L, 7L, 23L, 27L, 4L, NA,
27L, 22L, 4L, 6L, 26L, 26L, 6L, 27L, 27L, 7L, 1L, 4L, 26L, 6L,
4L, 13L, NA, 24L, 2L, 2L, 2L, 2L, 4L, 6L, 28L, 3L, 3L, 6L, NA,
1L, 2L, 1L, 2L, 2L, 3L, 25L, 23L, 2L, 4L, 28L, 28L, 3L, 28L,
28L, 2L, 2L, 28L, 28L, 6L, 1L, 28L, 2L, 2L, 4L, 26L, 6L, 2L,
28L, 2L, 25L, 2L, 7L, 6L, 27L, 28L, NA, NA, 27L, 28L, 6L, 4L,
28L, 26L, 6L, 13L, 1L, 2L, 4L, 4L, 28L, 6L, 2L, 23L, 26L, 2L,
7L, 2L, 4L, NA, 2L, 27L, 7L, 26L, 2L, 13L, 1L, 6L, 27L, 23L,
26L, 22L, 6L, 2L, 27L, 2L, 28L, 2L, 2L, 27L, 28L, 24L, 27L, 6L,
27L, NA, 27L, 6L, 6L, 26L, 2L, 28L, 7L, NA, 26L, 26L, 7L, 6L,
24L, 2L, 6L, 23L, 26L, 27L, 26L, 28L, 28L, 26L, 2L, 23L, 6L,
6L, 27L, 25L, 21L, 6L, NA, 2L, 28L, 4L, 27L, 23L, 1L, 23L, 6L,
13L, 7L, 2L, 26L, 28L, 28L, 24L, 6L, 2L, 25L, 26L, 4L, 26L, 26L,
23L, 1L, 28L, 4L, 2L, 27L, 7L, 28L, 4L, 27L, NA, 6L, 7L, 15L,
26L, 28L, 15L, 26L, 24L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 26L, 1L,
2L, 1L, 2L, 1L, 2L, 2L, 23L, 28L, 3L, 2L, 15L, 24L, 28L, 15L,
2L, 15L, 26L, 15L, 28L, 13L, 2L, NA, 28L, 2L, 25L, 27L, 28L,
2L, 2L, 28L, 3L, NA, 2L, 28L, 15L, 27L, 24L, 3L, 13L, 2L, 2L,
15L, 28L, 15L, 28L, 28L, 1L, 24L, 2L, 13L, 28L, 28L, 1L, 15L,
NA, 28L, 2L, 1L, 3L, 13L, 15L, 26L, 26L, 27L, 2L, 6L, 1L, 26L,
26L, 2L, 28L, 23L, 13L, 1L, 27L, 2L, 15L, 2L, 2L, NA, 1L, 22L,
2L, NA, 1L, 1L, 23L, 2L, 26L, 24L, 28L, 27L, 2L, 26L, NA, 2L,
27L, 2L, 2L, 2L, 2L, 13L, 25L, 2L, 2L, NA, 26L, 24L, 23L, 2L,
2L, 26L, 24L, 28L, 2L, 1L, 21L, 1L, 26L, 1L, 2L, 15L, 2L, 28L,
26L, 27L, 1L, 1L, 1L, 27L, 24L, 28L, 24L, 1L, 24L, 26L, 1L, 2L,
15L, 2L, 23L, 27L, 26L, 1L, 24L, 24L, 27L, 1L, 26L, 26L, 1L,
2L, 21L, 28L, 1L, 2L, 27L, 1L, NA, 3L, 1L, 27L, 2L, 15L, 15L,
2L, 13L, 26L, 1L, 1L, NA, 28L, 13L, 15L, 26L, 1L, 3L, 1L, 3L,
2L, NA, 26L, 15L, 26L, 2L, 13L, 2L, 27L, 1L, 2L, 3L, 25L, 1L,
25L, 26L, 15L, 15L, 1L, 15L, 15L, 15L, 26L, 2L, 2L, 27L, 3L,
2L, 23L, 24L, 15L, NA, 2L, 15L, 28L, 15L, 28L, 28L, 2L, 23L,
13L, 24L, 2L, 27L, 2L, 3L, 2L, 28L, NA, 3L, 1L, 15L, 2L, 28L,
1L, 1L, 3L, 2L, 2L, 27L, 13L, 26L, 26L, 15L, 1L, 28L, 1L, 2L,
26L, 2L, 25L, 26L, 2L, 1L, 2L, 13L, NA, 28L, 1L, 13L, 28L, 1L,
13L, 23L, 23L, 1L, 2L, NA, 28L, 3L, 28L, 13L, 28L, 26L, 15L,
3L, 28L, 9L, 26L, 28L, 23L, 2L, 1L, 13L, 2L, 28L, 1L, 15L, 1L,
28L, 1L, 25L, 2L, NA, 26L, 2L, 2L, 26L, 28L, 2L, 23L, 13L, 28L,
28L, 1L, 3L, 26L, 3L, 28L, 25L, 21L, 1L, 1L, 28L, 28L, 26L, 2L,
27L, 1L, 21L, NA, 26L, 28L, 15L, 2L, 2L, 13L, 2L, 28L, 2L, 3L,
26L, 3L, 23L, 27L, 3L, 23L, 2L, 2L, 26L, 2L, 24L, 1L, 1L, 1L,
2L, 25L, 26L, 24L, 1L, 1L, 25L, 21L, 13L, 27L, 2L, 24L, 24L,
2L, 2L, 2L, 26L, 13L, 27L, 26L, 28L, 2L, 2L, 2L, 26L, 28L, 25L,
21L, 1L, 1L, 26L, 2L, 1L, 1L, 2L, 27L, 24L, 28L, 26L, 1L, 26L,
24L, 2L, 28L, 26L, 1L, 28L, 28L, 26L, 26L, 2L, 24L, 24L, 21L,
2L, 3L, 25L, 28L, 2L, 1L, 2L, 27L, 24L, 28L, NA, 26L, 24L, 1L,
2L, 2L, 26L, 1L, 26L, 1L, 2L, 1L, 1L, 2L, 27L, 1L, 2L, 27L, 26L,
1L, 26L, 1L, 2L, 1L, 28L, 1L, 3L, 26L, 2L, 26L, 26L, NA, 1L,
28L, 26L, 24L, 1L, 26L, 1L, 1L, 1L, 1L, 24L, 26L, 2L, 28L, 1L,
28L, 3L, 26L, 2L, 27L, 24L, 2L, 25L, 1L, 2L, 23L, 2L, 28L, 26L,
23L, 2L, 2L, 2L, 2L, 28L, 2L, 24L, 1L, 26L, 26L, 2L, 2L, 23L,
24L, 27L, 21L, 2L, 2L, 27L, 24L, 23L, 24L, 2L, 27L, 26L, 28L,
13L, 27L, 26L, 2L, 2L, 24L, 27L, 23L, 1L, 24L, 2L, 13L, NA, 2L,
26L, 25L, 2L, 26L, 28L, 2L, 24L, 28L, 1L, 2L, 23L, 15L, 26L,
2L, 3L, 26L, 2L, 15L, 2L, 1L, 1L, 21L, 2L, 1L, 2L, 13L, 1L, 2L,
13L, 26L, 1L, 27L, 23L, 1L, 2L, 1L, 2L, 28L, 15L, 13L, 1L, 1L,
28L, 13L, 1L, 2L, 15L, 27L, 2L, 28L, 26L, 26L, 28L, 1L, 24L,
28L, 2L, 15L, 13L, 15L, 28L, 26L, 23L, 2L, 2L, 3L, 2L, 23L, 2L,
23L, 15L, 13L, 21L, 15L, 23L, 1L, 27L, 27L, 2L, 21L, 15L, 15L,
1L, 2L, 15L, 1L, 2L, 15L, 2L, 3L, 2L, 2L, 15L, 26L, 23L, 2L,
15L, 2L, 2L, 2L, 15L, 15L, 1L, 2L, 15L, 26L, 3L, 15L, 1L, 2L,
2L, 26L, 1L, 24L, 3L, 26L, 2L, 2L, 2L, 15L, 2L, 26L, 15L, 26L,
2L, 26L, 22L, NA, 1L, 27L, 2L, 2L, 26L, 28L, 13L, 3L, 1L, 1L,
1L, 15L, NA, 2L, 24L, 26L, 22L, 28L, 1L, 13L, 13L, NA, 3L, 8L,
21L, 1L, 1L, 15L, 15L, 1L, 26L, NA, 2L, 28L, 3L, 28L, NA, 23L,
26L, 15L, 15L, 2L, NA, 15L, 1L, 3L, 15L, 26L, 13L, 2L, 2L, 1L,
2L, 15L, 1L, 2L, 24L, 2L, 24L, 25L, 3L, 28L, 2L, 15L, 1L, NA,
28L, 3L, 1L, 28L, 2L, 26L, 2L, 2L, 1L, 22L, 15L, 3L, 24L, 26L,
2L, 24L, 1L, 24L, 3L, 13L, 28L, 1L, 2L, 13L, 1L, 2L, 28L, 24L,
2L, 1L, 2L, 1L, 1L, 15L, 26L, 2L, 2L, 3L, 28L, 2L, 22L, NA, 1L,
2L, 26L, 3L, 1L, 1L, 2L, 1L, 26L, 26L, 26L, 2L, 15L, 2L, 3L,
28L, 1L, 2L, 2L, 2L, NA, 26L, NA, 15L, 24L, NA, 1L, 27L, 2L,
2L, 27L, 27L, 2L, 23L, 2L, 28L, 13L, 2L, 28L, 2L, 2L, 1L, 28L,
27L, 2L, 27L, 15L, 13L, 26L, 15L, 15L, 1L, 26L, 1L, NA, 26L,
28L, 1L, 1L, 1L, 24L, NA, 28L, 1L, 1L, 2L, 15L, 25L, 2L, 1L,
15L, 27L, 3L, 1L, NA, NA, 26L, 1L, 13L, 26L, NA, NA, 2L, 23L,
27L, 24L, 26L, 28L, 25L, 3L, 26L, 1L, 1L, 28L, 1L, 2L, 24L, 2L,
1L, 2L, 2L, 15L, 1L, 1L, 15L, 28L, 15L, 15L, 26L, 22L, 28L, 2L,
28L, 1L, 24L, 28L, 28L, 15L, 15L, 3L, 15L, 24L, 26L, 28L, 1L,
24L, 27L, 3L, 1L, 3L, 2L, 13L, 1L, 28L, 13L, NA, 1L, 1L, 28L,
28L, 2L, 26L, 13L, 28L, 24L, 2L, 13L, 15L, NA, 1L, 13L, 1L, 1L,
2L, 2L, 1L, 27L, 2L, 2L, 26L, 2L, 15L, 1L, 26L, 24L, 1L, 2L,
13L, 2L, 1L, 2L, 2L, 2L, 3L, 2L, 28L, 28L, 1L, 1L, 15L, 13L,
26L, 1L, 28L, 1L, NA, 2L, 26L, 3L, 23L, 2L, 2L, NA, 1L, 28L,
2L, 3L, 2L, 1L, 2L, 1L, 2L, NA, 15L, 2L, NA, 23L, 3L, 15L, 2L,
28L, 23L, 13L, 2L, 2L, 1L, 3L, 1L, 2L, 28L, NA, 2L, 28L, 22L,
13L, 2L, 27L, 26L, 15L, 1L, 2L, 13L, 1L, 2L, 13L, 15L, 15L, 26L,
15L, 13L, 2L, 3L, 24L, 23L, 13L, 15L, 26L, 1L, 26L, 21L, 23L,
2L, 13L, 26L, 2L, 26L, 3L, 13L, 28L, 1L, 13L, 26L, 2L, 2L, 26L,
2L, 27L, 1L, 15L, 1L, 28L, 27L, 13L, 28L, 28L, 28L, 26L, NA,
21L, 3L, 27L, 15L, 1L, 28L, 28L, 23L, 3L, 23L, 3L, 24L, 9L, 2L,
9L, 23L, 27L, 26L, 24L, 26L, 2L, 28L, NA, 26L, NA, 2L, 28L, 2L,
24L, 28L, 9L, 27L, 24L, 6L, 13L, NA, 2L, 24L, 24L, 22L, 28L,
9L, 24L, NA, 24L, 24L, 2L, 24L, 23L, 28L, 28L, 26L, 26L, 2L,
8L, 1L, 26L, 22L, 2L, 23L, 1L, 27L, 22L, 2L, 26L, 15L, 2L, 24L,
2L, 2L, 2L, 15L, 26L, 26L, 8L, 9L, 2L, 8L, 2L, 26L, 2L, 8L, 15L,
25L, 8L, 15L, 15L, 2L, 1L, 8L, 9L, NA, 23L, 26L, 9L, 9L, 26L,
9L, 26L, 9L, 13L, 8L, 25L, 8L, 1L, 28L, 23L, 9L, 2L, 27L, 8L,
28L, 15L, 9L, 24L, 9L, 28L, 26L, 8L, 9L, 2L, 9L, 8L, 3L, 28L,
15L, 8L, 15L, NA, 2L, 27L, 2L, NA, 28L, 28L, 8L, 8L, 1L, 15L,
8L, 2L, 2L, 8L, 26L, NA, NA, 27L, 28L, 9L, 26L, 15L, 6L, 2L,
2L, 2L, NA, 26L, 26L, 8L, 15L, NA, 26L, 8L, 27L, 9L, 27L, 28L,
26L, 28L, 8L, 15L, 8L, 8L, 3L, 15L, NA, 9L, 8L, 9L, 15L, 9L,
28L, 28L, 9L, 9L, 26L, 28L, 28L, 2L, 2L, 26L, 2L, 1L, 1L, 2L,
1L, 2L, 23L, 25L, 3L, 2L, 15L, 28L, 26L, 1L, 28L, 26L, 23L, 2L,
1L, 25L, 26L, 24L), levels = c("PP ", "PSOE ", "Ciudadanos ",
"En Com├║ Podem ", "M├®s Comprom├¡s", "ERC ", "JxCat ",
"EAJ-PNV", "EH Bildu ", "CCa-NC ", "Na+ ", "PACMA ",
"VOX ", "CUP ", "Unidas Podemos ", "BNG ", "PRC ",
"Más País ", "En Común-Unidas Podemos ",
"Teruel Existe ", "Nulo ", "No tenía derecho a voto ",
"No tenía edad ", "Otros partidos ", "En blanco ", "No votó ",
"No recuerda ", "N.C. "), class = "factor"), CIS.P3 = structure(c(3L,
3L, 3L, 3L, 3L, 2L, 1L, 3L, 2L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 1L, 2L,
2L, 3L, 3L, 2L, 1L, 2L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L,
1L, 2L, 3L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 3L, 3L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 2L, 1L, 3L, 3L, 2L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 3L, 3L,
3L, 2L, 3L, 3L, 1L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 3L, 2L, 3L, 1L,
2L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L,
3L, 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2L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 4L, 3L, 3L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 3L,
3L, 3L, 2L, 2L, 1L, 2L, 2L, 3L, 1L, 3L, 2L, 2L, 3L, 1L, 3L, 2L,
2L, 3L, 3L, 3L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 3L, 1L, 3L, 2L, 3L,
3L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 2L, 2L, 2L, 2L,
2L, 1L, 2L, 3L, 2L, 3L, 2L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 1L,
1L, 1L), levels = c("Mejor", "(NO LEER) Igual", "Peor", "N.S.",
"N.C."), class = "factor")), class = "data.frame", row.names = c(NA,
-2787L))
The following code does the job:
library(tidyverse)
library(haven)
library(labelled)
CIS = read_spss("CISData.sav") %>%
mutate(
P3 = to_factor(P3),
RECUERDO = to_factor(RECUERDO)) %>%
mutate(P3 = sub("\\(NO LEER\\) ", "", P3))
include = c("PSOE", "PP", "VOX", "Unidas Podemos", "Ciudadanos")
CISb = CIS %>%
filter(RECUERDO %in% include) %>%
group_by(RECUERDO, P3) %>%
tally() %>%
mutate(pct = n/sum(n))
plot2 = ggplot(CISb, aes(x = pct, y = RECUERDO)) +
geom_bar(stat = "identity") +
facet_wrap(~P3, scales = "free_x") +
theme_bw() +
labs(x = "Percentage of Party's Voters in Each Response", y = "Voting Preference in 2019 General Elections",
title = "Current VS Past Individual Situation Based on Voting Preference")
plot2
I am trying to run lme4 package in R. I have 10 Lines in total with four plants for each line in each of the two replications. But some of the plants died and there are some missing values. Weight is the response variable. Here are some lines from the data:
Line Rep Weight PLANT
Line 1 1 NA 1
Line 1 1 NA 2
Line 1 1 NA 3
Line 1 1 NA 4
Line 2 1 26 1
Line 2 1 26 2
Line 2 1 26 3
Line 2 1 27 4
Line 1 2 26 1
Line 1 2 28 2
Line 1 2 26 3
Line 1 2 25 4
Line 2 2 24 1
Line 2 2 26 2
Line 2 2 25 3
Line 2 2 NA 4
I want to run linear mixed model using lme4 package so I tried running:
lme4 <- lmer(Weight ~ 1 + (1|Rep:Plant), data=Data)
But I got an error:
boundary (singular) fit: see ?isSingular
> dput(Data)
structure(list(Line = c("Line 1", "Line 1", "Line 1", "Line 1",
"Line 2", "Line 2", "Line 2", "Line 2", "Line 1", "Line 1", "Line 1",
"Line 1", "Line 2", "Line 2", "Line 2", "Line 2"), Rep = c(1,
1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2), Weight = c(NA,
NA, NA, NA, 26, 26, 26, 27, 26, 28, 26, 25, 24, 26, 25, NA),
PLANT = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)), row.names = c(NA,
-16L), class = c("tbl_df", "tbl", "data.frame"))
I am using it for the first time and I am not sure about the error. I will appreciate any help!
Your model did fit, but it generated that warning because your random effects are very small. You can read more about this in this post or the help page
Let us look at your data:
ggplot(Data,aes(x=PLANT,y=Weight,col=Rep)) + geom_jitter() + geom_boxplot(alpha=0.2) + facet_wrap(~Rep)
The effects of PLANT and in combination with Rep is extremely small. Let's look at the fitted model:
fit = lmer(Weight ~ 1 + (1|PLANT:Rep),data=Data)
boundary (singular) fit: see ?isSingular
ranef(fit)
$`PLANT:Rep`
(Intercept)
1:1 0
1:2 0
2:1 0
2:2 0
3:1 0
3:2 0
4:1 0
4:2 0
This is exactly what happened. So we can try to account for some other effects and we still see very small coefficients:
fit = lmer(Weight ~ Line + (1|Rep:PLANT),data=Data)
ranef(fit)
$`Rep:PLANT`
(Intercept)
1:1 1.397563e-19
1:2 2.811371e-19
1:3 8.112169e-20
1:4 1.813251e-19
2:1 -1.725964e-19
2:2 -2.463986e-20
2:3 -2.027357e-19
2:4 -2.833681e-19
The takehome message is, there's no really systematic effect coming from PLANT, so you don't need to specify a highly complicated model, do something like:
fit = lmer(Weight ~ Line + (1|Rep),data=Data)
The data in case anyone is interested:
Data = structure(list(Line = structure(c(1L, 1L, 1L, 1L, 12L, 12L, 12L,
12L, 23L, 23L, 23L, 23L, 34L, 34L, 34L, 34L, 45L, 45L, 45L, 45L,
56L, 56L, 56L, 56L, 65L, 65L, 65L, 65L, 66L, 66L, 66L, 66L, 67L,
67L, 67L, 67L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L,
9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 13L,
13L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L,
16L, 16L, 8L, 8L, 8L, 8L, 66L, 66L, 66L, 66L, 17L, 17L, 17L,
17L, 18L, 18L, 18L, 18L, 9L, 9L, 9L, 9L, 19L, 19L, 19L, 19L,
20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 24L,
24L, 24L, 24L, 25L, 25L, 25L, 25L, 2L, 2L, 2L, 2L, 26L, 26L,
26L, 26L, 27L, 27L, 27L, 27L, 10L, 10L, 10L, 10L, 28L, 28L, 28L,
28L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L,
67L, 67L, 67L, 67L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L,
33L, 33L, 33L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 37L, 37L,
37L, 37L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L, 40L, 40L, 40L,
40L, 25L, 25L, 25L, 25L, 19L, 19L, 19L, 19L, 24L, 24L, 24L, 24L,
41L, 41L, 41L, 41L, 42L, 42L, 42L, 42L, 30L, 30L, 30L, 30L, 43L,
43L, 43L, 43L, 44L, 44L, 44L, 44L, 22L, 22L, 22L, 22L, 46L, 46L,
46L, 46L, 47L, 47L, 47L, 47L, 17L, 17L, 17L, 17L, 48L, 48L, 48L,
48L, 49L, 49L, 49L, 49L, 27L, 27L, 27L, 27L, 23L, 23L, 23L, 23L,
50L, 50L, 50L, 50L, 51L, 51L, 51L, 51L, 52L, 52L, 52L, 52L, 41L,
41L, 41L, 41L, 7L, 7L, 7L, 7L, 46L, 46L, 46L, 46L, 11L, 11L,
11L, 11L, 33L, 33L, 33L, 33L, 53L, 53L, 53L, 53L, 54L, 54L, 54L,
54L, 13L, 13L, 13L, 13L, 38L, 38L, 38L, 38L, 4L, 4L, 4L, 4L,
37L, 37L, 37L, 37L, 55L, 55L, 55L, 55L, 57L, 57L, 57L, 57L, 44L,
44L, 44L, 44L, 58L, 58L, 58L, 58L, 59L, 59L, 59L, 59L, 12L, 12L,
12L, 12L, 47L, 47L, 47L, 47L, 48L, 48L, 48L, 48L, 60L, 60L, 60L,
60L, 21L, 21L, 21L, 21L, 18L, 18L, 18L, 18L, 28L, 28L, 28L, 28L,
26L, 26L, 26L, 26L, 61L, 61L, 61L, 61L, 31L, 31L, 31L, 31L, 59L,
59L, 59L, 59L, 52L, 52L, 52L, 52L, 29L, 29L, 29L, 29L, 62L, 62L,
62L, 62L, 63L, 63L, 63L, 63L, 54L, 54L, 54L, 54L, 55L, 55L, 55L,
55L, 53L, 53L, 53L, 53L, 51L, 51L, 51L, 51L, 50L, 50L, 50L, 50L,
64L, 64L, 64L, 64L, 20L, 20L, 20L, 20L, 58L, 58L, 58L, 58L, 16L,
16L, 16L, 16L, 57L, 57L, 57L, 57L, 14L, 14L, 14L, 14L, 63L, 63L,
63L, 63L, 64L, 64L, 64L, 64L, 61L, 61L, 61L, 61L, 36L, 36L, 36L,
36L, 40L, 40L, 40L, 40L, 6L, 6L, 6L, 6L, 39L, 39L, 39L, 39L,
45L, 45L, 45L, 45L, 15L, 15L, 15L, 15L, 1L, 1L, 1L, 1L, 42L,
42L, 42L, 42L, 43L, 43L, 43L, 43L, 65L, 65L, 65L, 65L, 49L, 49L,
49L, 49L, 56L, 56L, 56L, 56L, 3L, 3L, 3L, 3L, 62L, 62L, 62L,
62L, 35L, 35L, 35L, 35L, 5L, 5L, 5L, 5L, 60L, 60L, 60L, 60L,
34L, 34L, 34L, 34L), .Label = c("Line1", "Line10", "Line11",
"Line12", "Line13", "Line14", "Line15", "Line16", "Line17", "Line18",
"Line19", "Line2", "Line20", "Line21", "Line22", "Line23", "Line24",
"Line25", "Line26", "Line27", "Line28", "Line29", "Line3", "Line30",
"Line31", "Line32", "Line33", "Line34", "Line35", "Line36", "Line37",
"Line38", "Line39", "Line4", "Line40", "Line41", "Line42", "Line43",
"Line44", "Line45", "Line46", "Line47", "Line48", "Line49", "Line5",
"Line50", "Line51", "Line52", "Line53", "Line54", "Line55", "Line56",
"Line57", "Line58", "Line59", "Line6", "Line60", "Line61", "Line62",
"Line63", "Line64", "Line65", "Line66", "Line67", "Line7", "Line8",
"Line9"), class = "factor"), Rep = 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, 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, 2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L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 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, 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("1", "2"), class = "factor"), Weight = c(NA,
NA, NA, NA, 26L, 26L, 26L, 27L, NA, NA, NA, NA, 26L, 28L, 26L,
25L, 22L, 17L, 20L, 20L, 28L, 20L, 27L, 26L, 22L, 25L, 21L, 25L,
18L, 18L, 19L, 18L, 24L, 28L, 23L, 30L, 29L, 25L, 26L, 27L, NA,
NA, NA, NA, 29L, 30L, 29L, 30L, NA, NA, NA, NA, 33L, NA, NA,
NA, 21L, 23L, 18L, 23L, 32L, 29L, 30L, 30L, 18L, 19L, 21L, 21L,
25L, 25L, 25L, 26L, 26L, 27L, NA, NA, 29L, 29L, 27L, 29L, 26L,
NA, NA, NA, 26L, 20L, 23L, 27L, NA, NA, NA, NA, 32L, 32L, 30L,
30L, 20L, 20L, 20L, 19L, 22L, 21L, 22L, 22L, 24L, 23L, 23L, 25L,
20L, 25L, NA, NA, 27L, 26L, NA, NA, NA, NA, NA, NA, 30L, 28L,
NA, NA, 25L, 26L, 27L, 26L, NA, NA, NA, NA, 20L, 19L, NA, NA,
19L, 27L, 26L, 29L, 26L, 29L, 31L, 29L, 25L, 25L, 24L, 25L, 26L,
25L, 26L, 26L, 25L, 24L, 24L, 28L, 22L, 26L, 24L, 28L, 29L, 30L,
26L, NA, NA, NA, NA, NA, 26L, 24L, 24L, 24L, NA, NA, NA, NA,
NA, NA, NA, NA, 30L, 30L, 30L, 31L, 24L, 25L, 28L, 22L, 28L,
31L, 30L, NA, 31L, 30L, 29L, 25L, 25L, 22L, 24L, 20L, 30L, 30L,
30L, 29L, 26L, 32L, 28L, 29L, 20L, 15L, 15L, 11L, 25L, 24L, 24L,
24L, 26L, 29L, 31L, 30L, 24L, 28L, 20L, 22L, 29L, 26L, 26L, 28L,
27L, 27L, 27L, 26L, 21L, 22L, 21L, NA, 28L, 29L, 24L, 24L, 28L,
29L, 28L, 27L, 28L, 29L, 27L, 29L, NA, NA, NA, NA, 22L, 26L,
21L, 21L, 26L, 30L, 28L, 30L, 27L, 26L, 28L, 26L, 25L, 25L, 26L,
26L, 27L, 26L, 23L, 29L, NA, NA, NA, NA, 27L, 23L, 29L, 23L,
28L, 29L, 28L, 26L, 20L, NA, NA, NA, 28L, 23L, 26L, 21L, 28L,
26L, 26L, 29L, 20L, 27L, 20L, 26L, 29L, 26L, 28L, 28L, 30L, 27L,
NA, NA, 26L, 21L, 26L, 25L, 27L, 26L, 27L, 24L, 25L, 20L, 21L,
20L, 25L, 25L, 31L, 24L, 29L, 28L, 31L, 27L, 25L, 28L, 26L, 26L,
NA, NA, NA, NA, 24L, 25L, 23L, 27L, 20L, 26L, 25L, 25L, 29L,
28L, 29L, 29L, 26L, 27L, 25L, 28L, NA, NA, NA, NA, 26L, 28L,
NA, NA, 21L, 20L, 31L, 25L, 31L, 28L, 30L, 29L, 23L, 25L, 24L,
28L, 25L, 22L, 25L, 25L, 28L, 29L, 28L, 29L, 26L, 24L, 25L, 26L,
29L, 27L, NA, NA, 26L, 29L, 29L, 30L, 25L, 24L, 25L, 24L, 28L,
25L, 29L, 28L, 24L, 24L, 24L, 24L, 28L, 30L, 27L, 27L, 26L, 25L,
25L, 25L, 25L, 25L, 28L, 25L, 25L, 30L, 28L, 25L, 22L, 24L, 25L,
24L, NA, NA, NA, NA, 5L, 7L, 4L, 5L, 21L, 20L, 22L, 24L, 25L,
27L, 25L, 28L, 32L, 31L, NA, NA, 19L, 26L, 20L, NA, 26L, 26L,
30L, 25L, 28L, 31L, 30L, 26L, 5L, 8L, 4L, 8L, 25L, 25L, 28L,
25L, 28L, 28L, 27L, 26L, 30L, 27L, 27L, 24L, 32L, 29L, 31L, 25L,
30L, 30L, 27L, 28L, 16L, 20L, 16L, 21L, 25L, 22L, 25L, 20L, 24L,
25L, 18L, 25L, 25L, 26L, 29L, 29L, 21L, 20L, 22L, 21L, 19L, 22L,
19L, 21L, 28L, 25L, 26L, 24L, 28L, 26L, 24L, 25L, NA, NA, NA,
NA, 25L, NA, NA, NA, 23L, 21L, 19L, 23L, 25L, 24L, 25L, NA, 22L,
30L, 29L, 26L, 25L, 25L, 24L, 24L), PLANT = structure(c(1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 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1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L,
8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L,
7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L,
3L, 7L, 8L, 1L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L,
6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L,
5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L,
2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L,
4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L,
6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L,
5L, 6L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L,
7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L,
3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L,
1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L,
8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L,
7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L
), .Label = c("24", "12", "21", "11", "13", "14", "22", "23"
), class = "factor")), row.names = c(NA, -536L), class = "data.frame")
I cannot figure out how to use a loop to plot one histogram for each unique combination of levels from TWO factors.
Here is my data: https://www.dropbox.com/sh/exsjhu23fnpwf4r/AABvitLBN1nRMpXcyYMVIOIDa?dl=0
# perhaps need to have factors
df$freq <- as.factor(df$freq)
df$time <- as.factor(df$time)
I learned how to use a loop to plot histograms for ONE factor levels:
# space for plots
windows(width=19, height=10)
par(las=1, cex.lab=0.75, cex.axis=0.6, bty="n", mgp=c(1, 0.6, 0),
oma=c(2, 4, 2, 0) + 0.1, mar=c(4, 0, 3, 3) + 0.1)
a <- layout(matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21), nrow=3, ncol=7, byrow=T))
layout.show(a)
# loop
for (i in 1:length(unique(df$freq))) {
value <- subset(df, freq == unique (df$freq)[i])
hist(value$thr, main=paste0("freq: ", unique(df$freq)[i]))
}
I tried variations of this loop for TWO factors but that unfortunately does not work:
for (i in 1:length(unique(df[c("freq", "time")]))) {
value <- subset(df, freq == unique (df$freq)[i] & time == unique(df$time)[i])
hist(value$thr, main=paste0("freq: ", unique(df$freq)[i]))
}
I would also like to learn how to label each histogram based on the levels of TWO factors (not just one)...
It's more convenient to use by here.
For the titles we prefer characters to factors.
df1[c("freq", "time")] <- lapply(df1[c("freq", "time")], as.character)
Then open windows,
windows(width=19, height=10)
par(las=1, cex.lab=0.75, cex.axis=0.6, bty="n", mgp=c(1, 0.6, 0),
oma=c(2, 4, 2, 0) + 0.1, mar=c(4, 0, 3, 3) + 0.1)
a <- layout(matrix(1:21, 3, 7))
layout.show(a)
and plot.
by(df1, df1[c("freq", "time")], function(x)
hist(x$thr, main=paste("freq:", paste(x[1, c(1, 3)], collapse=","))))
Result
Edit
To get the specific order we probably have to do some more stuff.
df1[c("freq", "time")] <- lapply(df1[c("freq", "time")], as.character)
windows(width=19, height=10)
par(las=1, cex.lab=0.75, cex.axis=0.6, bty="n", mgp=c(1, 0.6, 0),
oma=c(2, 4, 2, 0) + 0.1, mar=c(4, 0, 3, 3) + 0.1)
a <- layout(matrix(1:21, 3, 7, byrow=TRUE)) # with byrow
layout.show(a)
l <- split(df1, df1[c("freq", "time")])
m <- t(sapply(l, function(x) x[1, c(1, 3)])) # matrix of first rows of each subset
m[, 2] <- sub("m", "", m[, 2]) # use the values...
m <- apply(m, 1:2, as.numeric) # ... make numeric
Now we obtain the histograms within a lapply over the list ordered by m.
lapply(l[order(m[, 2], m[, 1])], function(x)
hist(x$thr, main=paste("freq:", paste(x[1, c(1, 3)], collapse=","))))
New Result
Data
df1 <- structure(list(freq = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L), .Label = c("4",
"8", "12.5", "16", "20", "25", "31.5"), class = "factor"), thr = c(60L,
25L, 20L, 15L, 15L, 30L, 35L, 60L, 25L, 10L, 15L, 15L, 30L, 35L,
55L, 30L, 15L, 15L, 10L, 25L, 40L, 50L, 25L, 15L, 10L, 15L, 20L,
40L, 50L, 30L, 10L, 15L, 15L, 20L, 25L, 50L, 25L, 10L, 10L, 10L,
20L, 25L, 45L, 20L, 10L, 10L, 10L, 20L, 25L, 45L, 15L, 10L, 10L,
10L, 20L, 30L, 60L, 30L, 10L, 10L, 10L, 15L, 30L, 50L, 25L, 10L,
10L, 10L, 20L, 30L, 45L, 25L, 15L, 10L, 15L, 30L, 35L, 50L, 25L,
15L, 10L, 15L, 25L, 35L, 60L, 25L, 10L, 10L, 15L, 20L, 30L, 60L,
25L, 5L, 5L, 10L, 20L, 30L, 45L, 20L, 5L, 10L, 10L, 20L, 30L,
45L, 20L, 10L, 10L, 10L, 20L, 30L, 60L, 30L, 15L, 10L, 15L, 25L,
30L, 55L, 25L, 10L, 10L, 10L, 20L, 30L, 55L, 35L, 10L, 10L, 10L,
20L, 30L, 60L, 35L, 15L, 10L, 10L, 15L, 25L, 50L, 30L, 10L, 10L,
10L, 20L, 25L, 55L, 25L, 10L, 10L, 15L, 25L, 25L, 65L, 30L, 10L,
10L, 15L, 20L, 30L, 60L, 30L, 15L, 15L, 15L, 15L, 30L, 55L, 35L,
15L, 15L, 15L, 25L, 35L, 55L, 35L, 15L, 15L, 15L, 25L, 35L, 60L,
35L, 15L, 15L, 15L, 25L, 35L, 60L, 30L, 10L, 10L, 15L, 25L, 35L,
55L, 30L, 15L, 10L, 10L, 25L, 30L, 50L, 25L, 10L, 10L, 10L, 20L,
30L, 55L, 30L, 10L, 10L, 15L, 20L, 30L, 55L, 30L, 10L, 15L, 20L,
25L, 35L, 55L, 25L, 15L, 15L, 15L, 25L, 40L, 50L, 20L, 10L, 10L,
20L, 30L, 40L, 45L, 25L, 10L, 10L, 10L, 20L, 30L, 50L, 25L, 10L,
10L, 10L, 20L, 25L, 55L, 20L, 10L, 10L, 15L, 25L, 35L, 50L, 20L,
10L, 10L, 15L, 25L, 30L, 45L, 20L, 15L, 10L, 10L, 20L, 30L, 50L,
20L, 15L, 15L, 15L, 20L, 30L, 60L, 35L, 15L, 10L, 15L, 25L, 30L,
60L, 35L, 15L, 15L, 15L, 30L, 35L, 55L, 25L, 10L, 15L, 15L, 25L,
35L, 50L, 30L, 10L, 15L, 15L, 25L, 35L, 55L, 25L, 20L, 15L, 15L,
25L, 30L, 55L, 25L, 15L, 15L, 15L, 30L, 35L), time = 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, 1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L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L), .Label = c("3m", "6m", "9m"), class = "factor")), row.names = c(NA,
-322L), class = "data.frame")
I'm using this data set (at the bottom) to create a density plot, but am having issue with the factor and getting it to aggregate properly. I want the graph to look like this:
ggplot(sample, aes(as.numeric(value), colour=shortname)) + geom_density()
But I want the x-axis to have the actual labels of the factors. But when I use this:
ggplot(sample, aes(value, colour=shortname)) + geom_density()
the graph doesn't aggregate them into the two distinct values of the shortname variable.
What am I doing wrong? I've read about using scale_x_discrete(), but I don't think I should need to since I already have a factor...
UPDATE: Even if I use scale_x_discrete in the following way:
ggplot(sample, aes(value, colour=shortname)) + geom_density() + scale_x_discrete(breaks=1:27, labels=c("<A",LETTERS))
that just removes the x-axis labels all together...
Thank you in advance!
sample <- structure(list(shortname = 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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,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 17L, 12L, 16L, 21L, 2L, 21L, 19L,
22L, 12L, 15L, 22L, 19L, 16L, 13L, 19L, 24L, 15L, 24L, 23L, 12L,
24L, 21L, 15L, 16L, 16L, 18L, 18L, 8L, 23L, 8L, 21L, 24L, 13L,
10L, 18L, 1L, 7L, 14L, 13L, 21L, 16L, 10L, 15L, 21L, 17L, 18L,
18L, 21L, 14L, 9L, 22L, 14L, 11L, 16L, 13L, 18L, 12L, 1L, 23L,
8L, 15L, 18L, 11L, 10L, 20L, 16L, 12L, 10L, 22L, 25L, 24L, 7L,
19L, 13L, 16L, 16L, 20L, 3L, 13L, 21L, 12L, 16L, 13L, 15L, 1L,
19L, 12L, 20L, 12L, 11L, 20L, 7L, 22L, 18L, 19L, 9L, 10L, 24L,
10L, 13L, 5L, 16L, 19L, 20L, 19L, 18L, 19L, 19L, 13L, 12L, 21L,
20L, 13L, 21L, 3L, 12L, 19L, 17L, 16L, 9L, 21L, 18L, 24L, 2L,
12L, 13L, 14L, 7L, 16L, 10L, 21L, 15L, 21L, 11L, 18L, 3L, 16L,
15L, 22L, 10L, 16L, 21L, 19L, 17L, 20L, 22L, 17L, 20L, 2L, 24L,
12L, 18L, 19L, 24L, 26L, 17L, 20L, 15L, 12L, 10L, 16L, 12L, 12L,
15L, 19L, 14L, 22L, 12L, 7L, 16L, 1L, 20L, 18L, 24L, 19L, 22L,
3L, 16L, 19L, 22L, 5L, 19L, 17L, 16L, 13L, 22L, 3L, 14L, 12L,
9L, 5L, 16L, 14L, 15L, 12L, 2L, 12L, 19L, 20L, 18L, 10L, 3L,
20L, 4L, 16L, 19L, 1L, 14L, 24L, 9L, 14L, 1L, 12L, 6L, 1L, 22L,
11L, 13L, 19L, 16L, 22L, 25L, 3L, 21L, 21L, 22L, 3L, 21L, 18L,
23L, 24L, 2L, 21L, 15L, 15L, 16L, 11L, 13L, 25L, 11L, 17L, 15L,
7L, 23L, 21L, 4L, 1L, 14L, 19L, 13L, 10L, 18L, 3L, 13L, 17L,
12L, 7L, 21L, 17L, 17L, 17L, 17L, 10L, 21L, 24L, 22L, 12L, 22L,
12L, 24L, 17L, 16L, 21L, 19L, 16L, 16L, 16L, 21L, 13L, 1L, 7L,
21L, 11L, 13L, 10L, 21L, 11L, 25L, 1L, 11L, 3L, 24L, 13L, 13L,
15L, 7L, 21L, 16L, 24L, 16L, 8L, 19L, 13L, 18L, 18L, 22L, 19L,
16L, 16L, 15L, 5L, 4L, 14L, 8L, 15L, 18L, 13L, 14L, 12L, 19L,
16L, 3L, 16L, 17L, 1L, 19L, 20L, 19L, 1L, 19L, 20L, 22L, 8L,
12L, 13L, 24L, 16L, 14L, 21L, 25L, 22L, 4L, 16L, 16L, 15L, 16L,
8L, 14L, 12L, 11L, 5L, 13L, 19L, 27L, 3L, 18L, 12L, 13L, 19L,
7L, 10L, 15L, 23L, 11L, 3L, 24L, 18L, 15L, 16L, 14L, 16L, 22L,
11L, 11L, 20L, 18L, 14L, 20L, 21L, 3L, 10L, 19L, 14L, 16L, 8L,
12L, 16L, 8L, 21L, 26L, 13L, 6L, 9L, 2L, 15L, 1L, 12L, 24L, 3L,
21L, 24L, 8L, 18L, 20L, 3L, 19L, 12L, 15L, 8L, 18L, 14L, 19L,
10L, 20L, 17L, 12L, 17L, 19L, 14L, 10L, 7L, 11L, 12L, 3L, 19L,
1L, 16L, 11L, 8L, 3L, 10L, 15L, 21L, 27L, 3L, 3L, 19L, 5L, 17L,
22L, 10L, 3L, 15L, 19L, 19L, 18L, 23L, 1L, 22L, 9L, 22L, 19L,
12L, 18L, 10L, 10L, 9L, 14L, 2L, 27L, 21L, 4L, 18L, 1L, 2L, 16L,
3L, 21L, 19L, 24L, 12L, 12L, 19L, 13L, 16L, 19L, 20L, 12L, 20L,
13L, 9L, 15L, 22L, 14L, 5L, 22L, 15L, 3L, 9L, 3L, 12L, 2L, 12L,
12L, 22L, 15L, 9L, 3L, 21L, 14L, 5L, 5L, 10L, 5L, 5L, 1L, 7L,
21L, 19L, 22L, 1L, 9L, 1L, 21L, 18L, 15L, 14L, 21L, 6L, 19L,
15L, 16L, 5L, 5L, 10L, 20L, 5L, 8L, 19L, 3L, 16L, 5L, 7L, 17L,
16L, 19L, 2L, 20L, 15L, 9L, 17L, 21L, 19L, 13L, 3L, 13L, 12L,
21L, 16L, 15L, 17L, 16L, 19L, 8L, 17L, 14L, 1L, 1L, 22L, 19L,
24L, 20L, 10L, 17L, 1L, 17L, 1L, 17L, 13L, 15L, 21L, 6L, 3L,
18L, 20L, 15L, 4L, 16L, 8L, 12L, 10L, 13L, 13L, 22L, 11L, 12L,
1L, 21L, 21L, 5L, 5L, 16L, 11L, 20L, 21L, 20L, 21L, 20L, 19L,
20L, 15L, 25L, 9L, 1L, 12L, 21L, 9L, 24L, 3L, 12L, 24L, 8L, 16L,
15L, 9L, 20L, 15L, 5L, 10L, 1L, 16L, 16L, 12L, 9L, 20L, 10L,
19L, 12L, 3L, 20L, 22L, 11L, 16L, 16L, 22L, 19L, 19L, 22L, 14L,
14L, 12L, 5L, 14L, 19L, 18L, 19L, 18L, 3L, 10L, 20L, 14L, 1L,
13L, 18L, 13L, 1L, 22L, 23L, 19L, 13L, 18L, 9L, 16L, 15L, 17L,
21L, 15L, 18L, 1L, 14L, 14L, 1L, 14L, 9L, 16L, 12L, 22L, 14L,
2L, 22L, 19L, 21L, 16L, 16L, 11L, 19L, 13L, 3L, 16L, 16L, 20L,
18L, 1L, 19L, 11L, 17L, 19L, 12L, 15L, 10L, 11L, 13L, 7L, 14L,
14L, 14L, 15L, 15L, 16L, 14L, 22L, 20L, 17L, 19L, 19L, 13L, 16L,
12L, 15L, 20L, 22L, 17L, 20L, 16L, 10L, 15L, 15L, 12L, 12L, 14L,
20L, 5L, 19L, 2L, 13L, 15L, 17L, 9L, 14L, 18L, 2L, 10L, 14L,
12L, 14L, 12L, 18L, 17L, 13L, 8L, 22L, 12L, 21L, 12L, 13L, 3L,
14L, 26L, 4L, 3L, 1L, 7L, 10L, 19L, 16L, 16L, 15L, 13L, 15L,
16L, 11L, 21L, 12L, 11L, 15L, 1L, 16L, 1L, 17L, 6L, 1L, 16L,
7L, 11L, 2L, 5L, 16L, 5L, 12L, 13L, 12L, 13L, 13L, 12L, 20L,
21L, 21L, 12L, 19L, 21L, 18L, 12L, 15L, 22L, 19L, 16L, 16L, 3L,
14L, 1L, 7L, 13L, 16L, 11L, 7L, 12L, 16L, 16L, 12L, 22L, 1L,
13L, 4L, 8L, 16L, 5L, 11L, 10L, 1L, 21L, 10L, 19L, 12L, 13L,
16L, 12L, 15L, 19L, 13L, 1L, 1L, 2L, 6L, 16L, 14L, 15L, 15L,
16L, 4L, 12L, 16L, 10L, 19L, 12L, 5L, 6L, 10L, 3L, 14L, 1L, 12L,
4L, 11L, 16L, 10L, 20L, 4L, 13L, 10L, 1L, 9L, 2L, 7L, 9L, 18L,
10L, 26L, 14L, 2L, 14L, 10L, 11L, 13L, 1L, 21L, 16L, 9L, 22L,
12L, 12L, 16L, 15L, 12L, 8L, 15L, 20L, 11L, 16L, 15L, 12L, 12L,
16L, 2L, 9L, 12L, 14L, 20L, 1L, 10L, 7L, 10L, 18L, 16L, 12L,
15L, 12L, 14L, 3L, 14L, 6L, 10L, 1L, 11L, 9L, 5L, 12L, 12L, 1L,
8L, 20L, 7L, 21L, 20L, 22L, 20L, 7L, 12L, 9L, 7L, 13L, 19L, 15L,
15L, 18L, 16L, 1L, 10L, 19L, 2L, 13L, 6L, 24L, 1L, 22L, 16L,
11L, 7L, 5L, 19L, 15L, 14L, 12L, 19L, 14L, 12L, 15L, 24L, 15L,
10L, 4L, 14L, 16L, 3L, 21L, 1L, 19L, 14L, 17L, 12L, 21L, 3L,
12L, 16L, 18L, 14L, 15L, 15L, 14L, 1L, 2L, 17L, 1L, 14L, 16L,
15L, 14L, 10L, 14L, 17L, 17L, 12L, 17L, 11L, 14L, 16L, 1L, 1L,
19L, 12L, 24L, 15L, 19L, 14L, 8L, 3L, 22L, 1L, 16L, 15L, 19L,
8L, 15L, 12L, 8L, 14L, 8L, 12L, 7L, 13L, 2L, 13L, 10L, 15L, 15L,
17L, 1L, 26L, 24L, 21L, 25L, 14L, 10L, 13L, 9L, 13L, 18L, 19L,
16L, 21L, 16L, 17L, 14L, 14L, 11L, 17L, 16L, 12L, 17L, 14L, 6L,
24L, 11L, 11L, 11L, 12L, 15L, 13L, 22L, 11L, 17L, 3L, 12L, 17L,
14L, 10L, 11L, 9L, 21L, 18L, 19L, 20L, 24L, 7L, 12L, 22L, 3L,
17L, 10L, 1L, 20L, 1L, 1L, 12L, 2L, 14L, 2L, 17L, 19L, 1L, 10L,
12L, 16L, 15L, 3L, 12L, 16L, 12L, 15L, 17L, 24L, 15L, 16L, 8L,
12L, 14L, 21L, 9L, 23L, 3L, 19L, 16L, 19L, 16L, 16L, 13L, 13L,
3L, 9L, 17L, 1L, 1L, 16L, 11L, 15L, 7L, 7L, 14L, 8L, 14L, 20L,
15L, 16L, 1L, 12L, 9L, 16L), .Label = c("<A", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"), class = "factor")), .Names = c("shortname",
"value"), row.names = c(NA, 1156L), class = "data.frame")
You can get the desired behavior with:
ggplot(sample, aes(value, colour=shortname, group=shortname)) + geom_density()
Note the letter labels at the bottom of the plot, which weren't present with the as.numeric solution: