让我们有一个数据框...
library(tidyverse)
dates <- c("2019-03-01","2019-04-01","2019-05-01","2019-06-01","2019-07-01")
d <- data_frame(month = dates %>% factor(ordered = TRUE),subject = "Abc_14",taux = runif(length(dates)),volume = (runif(length(dates)) * 100) %>% as.integer())
d %>% glimpse()
Observations: 5
Variables: 4
$ month <ord> 2019-03-01,2019-04-01,2019-05-01,2019-06-01,2019-07-01
$ subject <chr> "Abc_14","Abc_14","Abc_14"
$ taux <dbl> 0.67040271,0.85711442,0.94608828,0.65138723,0.02835217
$ volume <int> 52,46,33,17,69
然后让这个失败的图出现:
d %>%
ggplot(aes(volume,taux)) +
geom_density2d(size = .2) +
geom_point(aes(fill = subject)) +
geom_smooth(method = "lm",se = FALSE) +
facet_wrap(facets = vars(month),scales = "free") +
scale_y_continuous(labels = scales::percent,breaks = seq(0,1,.2)) +
theme(legend.position = "none")
Error in prettyNum(.Internal(format(x,trim,digits,nsmall,width,3L,: argument 'nsmall' incorrect
似乎facet_wrap
与scale_y_continuous
之间存在冲突。排除其中任何一个,我都会得到结果。 我有什么办法让他们俩都保留?
没有scale_y_continous()
,我明白了,但是我确实需要百分比标签:
注意:实际数据框有大约200行,大约30个主题,大约10个月,并且缺少一些组合。它仍在增长。