作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
无论我如何尝试,我都无法使用ggridges
创建山脊线图。使用如下所示的数据框 graphing_dataframe
:
str(graphing_dataframe)
summary(graphing_dataframe)
> str(graphing_dataframe)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 14 obs. of 3 variables:
$ id : chr "00343" "00343" "00343" "00343" ...
$ week : num 14 1 2 3 4 5 6 7 8 9 ...
$ rating: num 14 4 12 8 14 19 16 16 7 8 ...
- attr(*, "spec")=
.. cols(
.. id = col_character(),
.. week = col_double(),
.. rating = col_double()
.. )
> summary(graphing_dataframe)
id week rating
Length:14 Min. : 1.00 Min. : 4.00
Class :character 1st Qu.: 4.25 1st Qu.: 8.00
Mode :character Median : 7.50 Median :10.50
Mean : 7.50 Mean :11.43
3rd Qu.:10.75 3rd Qu.:15.50
Max. :14.00 Max. :19.00
我的数据是:
structure(list(id = c("00343", "00343", "00343", "00343", "00343",
"00343", "00343", "00343", "00343", "00343", "00343", "00343",
"00343", "00343"), week = c(14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13), rating = c(14, 4, 12, 8, 14, 19, 16, 16, 7, 8, 9,
18, 9, 6)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-14L), spec = structure(list(cols = list(id = structure(list(), class = c("collector_character",
"collector")), week = structure(list(), class = c("collector_double",
"collector")), rating = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector"))), class = "col_spec"))
我的代码是:
ggplot(graphing_dataframe,
aes(x = rating, y = week, fill = ..x..)
) +
geom_density_ridges()
Picking joint bandwidth of 2.53
Error: geom_density_ridges requires the following missing aesthetics: y
我已尝试使用 unlist
per this question但这也行不通。
最佳答案
根据documentation,错误消息似乎有点误导。您需要为数值变量添加群体美感:
The grouping aesthetic does not need to be provided if a categorical variable is mapped onto the y axis, but it does need to be provided if the variable is numerical.
因此将 group = week
添加到 ggplot(aes(…))
应该可以解决问题。 (我自己也遇到了同样的问题。)
关于r - geom_密度_脊需要以下缺失的美感 : y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54147272/
我是一名优秀的程序员,十分优秀!