如何实现"geom_density_ridges"功能
How to implement the "geom_density_ridges" function
我想用我的数据生成一个与此 iris 数据集所示类似的图。
ggplot(iris, aes(x = Sepal.Length, y = Species)) +
geom_density_ridges(aes(fill = Species)) +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
在这里你可以看到我的数据集的截图。
ratio = c(0, 0.05, 0.1, 0.15, 0.2, 0.25, 0, 0.05, 0.1, 0.15, 0.2, 0.25)
frequency = c(12000, 12300, 9000, 4300, 2434, 18000, 11000, 12200, 8000, 4100, 2400, 15900)
concentration = c("200", "200", "200", "200", "200", "200", "100", "100", "100", "100", "100", "100")
df = cbind(ratio, frequency, concentration)
View(df)
df = as.data.frame(df)
ggplot(df, aes(x = ratio, y = frequency)) +
geom_density_ridges(aes(fill = df$concentration)) +
scale_fill_manual(values = c("#00AFBB", "#E7B800"))
不幸的是我的代码不起作用。我不知道我的错误在哪里。
这就是你想要的吗?
library(ggplot2); library(ggridges)
ggplot(df, aes(x = ratio, y = concentration,
height = frequency/10000, fill = concentration)) +
geom_ridgeline() +
scale_fill_manual(values = c("#00AFBB", "#E7B800"))
数据:
df = data.frame(stringsAsFactors = F,
ratio = c(0, 0.05, 0.1, 0.15, 0.2, 0.25, 0, 0.05, 0.1, 0.15, 0.2, 0.25),
frequency = c(12000, 12300, 9000, 4300, 2434, 18000, 11000, 12200, 8000, 4100, 2400, 15900),
concentration = c("200", "200", "200", "200", "200", "200", "100", "100", "100", "100", "100", "100"))
我想用我的数据生成一个与此 iris 数据集所示类似的图。
ggplot(iris, aes(x = Sepal.Length, y = Species)) +
geom_density_ridges(aes(fill = Species)) +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
在这里你可以看到我的数据集的截图。
ratio = c(0, 0.05, 0.1, 0.15, 0.2, 0.25, 0, 0.05, 0.1, 0.15, 0.2, 0.25)
frequency = c(12000, 12300, 9000, 4300, 2434, 18000, 11000, 12200, 8000, 4100, 2400, 15900)
concentration = c("200", "200", "200", "200", "200", "200", "100", "100", "100", "100", "100", "100")
df = cbind(ratio, frequency, concentration)
View(df)
df = as.data.frame(df)
ggplot(df, aes(x = ratio, y = frequency)) +
geom_density_ridges(aes(fill = df$concentration)) +
scale_fill_manual(values = c("#00AFBB", "#E7B800"))
不幸的是我的代码不起作用。我不知道我的错误在哪里。
这就是你想要的吗?
library(ggplot2); library(ggridges)
ggplot(df, aes(x = ratio, y = concentration,
height = frequency/10000, fill = concentration)) +
geom_ridgeline() +
scale_fill_manual(values = c("#00AFBB", "#E7B800"))
数据:
df = data.frame(stringsAsFactors = F,
ratio = c(0, 0.05, 0.1, 0.15, 0.2, 0.25, 0, 0.05, 0.1, 0.15, 0.2, 0.25),
frequency = c(12000, 12300, 9000, 4300, 2434, 18000, 11000, 12200, 8000, 4100, 2400, 15900),
concentration = c("200", "200", "200", "200", "200", "200", "100", "100", "100", "100", "100", "100"))