Reputation: 959
I am trying to make a density curve for my data with the following code:
ggplot(velar_nonnasal_low_f, aes(x = F2_difference, linetype = type)) +
geom_density() +
ggtitle("Density of F2 difference for /æ, ɛ/ for females") +
xlab("F2 difference") +
scale_fill_manual(name = "Place of Articulation")
This code has worked fine with previous data frames, but now it produces the plot below instead of a smooth curve. I apologize if this is an easily answerable question (I am still learning R), but I just can't figure out why ggplot is plotting the data this way.
Here is some code so that you can reproduce a small part of what my data looks like.
Edit: Here is reproducible code of my actual data.
type <- c("coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal", "coronal")
F2_difference <- c(46.992662, 18.174776, -90.708617, -59.842787, -147.212234, -272.596601, 38.560577, 64.413318, -107.797167, -148.581689, -207.521093, 37.117600, -110.178964, 209.738062, 456.686906, 39.369545, -29.394699, -36.435841, 2.056190, -22.414031, 4.705579, -188.352557, -212.596306, 159.445017, -139.284470, -278.304356, -121.685889, -118.666014, 804.253078, -42.737883, 203.878428, -34.867516, -221.979230, -128.715072, 85.145217
velar_nonnasal_low_f <- data.frame (type, F2_difference)
Upvotes: 1
Views: 332
Reputation: 2289
I think @navinkb is right in his comment. To replicate the graph you have I did this:
n <- 33
type <- c(rep("coronal", n),
rep("labial", 35 - n))
F2_difference <- c(46.992662, 18.174776, -90.708617, -59.842787, -147.212234, -272.596601, 38.560577,
64.413318, -107.797167, -148.581689, -207.521093, 37.117600, -110.178964, 209.738062,
456.686906, 39.369545, -29.394699, -36.435841, 2.056190, -22.414031, 4.705579, -188.352557,
-212.596306, 159.445017, -139.284470, -278.304356, -121.685889, -118.666014, 804.253078,
-42.737883, 203.878428, -34.867516, -221.979230, -128.715072, 85.145217)
velar_nonnasal_low_f <- data.frame (type, F2_difference)
library(plotly)
ggplot(velar_nonnasal_low_f, aes(x = F2_difference, linetype = type)) +
geom_density() +
ggtitle("Density of F2 difference for /æ, ɛ/ for females") +
xlab("F2 difference") +
scale_fill_manual(name = "Place of Articulation")
I get this:
But if I use the data you shared I get:
So maybe check the data?
Upvotes: 1