“continuous value supplied to discrete scale”错误通常出现在使用数据可视化库(如R语言的ggplot2)时。这个错误意味着你尝试将一个连续的值(如数值数据)映射到一个离散的刻度(如颜色、形状或填充)上,而这在逻辑上是不一致的。 2. 分析可能导致该错误的常见原因 错误的映射类型:在创建图表时,可能错误地将一个应...
使用scale_x_discrete函数更改x轴标签:在ggplot函数中添加scale_x_discrete函数来更改x轴标签。你可以使用labels参数来指定新的标签集合。例如,你可以使用scale_x_discrete(labels = c("标签1", "标签2", "标签3"))来将x轴标签更改为"标签1"、"标签2"和"标签3"。 以下是一个完整的示例代码: 代码语言:t...
scale_x_discrete(labels = vapply(my_labels, str_wrap, character(1), width = 10)) mpg %>% filter(class == 'pickup' | class == "suv" | class == "compact") %>% ggplot(aes(class, fill = factor(class))) + geom_bar() + scale_x_discrete(labels = setNames(str_wrap(my_labels...
install.packages("ggplot2")# Install & load ggplot2 packagelibrary("ggplot2") Example 1: Reproduce the ggplot2 Error: Continuous value supplied to discrete scale In this example, I’ll illustrate how to replicate the error message “Continuous value supplied to discrete scale” when drawing a ...
scale_x_discrete函数的另一个有用功能是从 x 轴消除一些元素并仅绘制其中的少数元素。在这种情况下,我们使用PlantGrowth数据集,其中列出了三类组。因此,我们可以输出只有trt2和trt1组的箱线图,如下面的代码片段所示。 library(ggplot2)library(gridExtra)p1<-ggplot(Loblolly,aes(x=Seed, y=height))+geom_boxpl...
问限制在使用时压缩标签和数据:scale_x_discrete( ggplot2 = c())ENR具有强大的统计计算功能和便捷的...
用scale_x_discrete替换轴标签library(ggplot2)ggplot(dat, aes(Sample, Abundance, fill=Class)) +theme_bw() +geom_bar(col="black", stat="identity", width=0.75) +scale_x_discrete(label = seq(100,300,100)) +facet_grid(vars(Transect),vars(Season))
every_nth = function(n) { return(function(x) {x[c(TRUE, rep(FALSE, n - 1))]}) } ggplot(mpg, aes(x = class, y = cyl)) + geom_point() + scale_x_discrete(breaks = every_nth(n = 3)) https://stackoverflow.com/questions/52919899/ggplot2-display-every-nth-value-on-discrete-...
并使用 ggplot2 库我做了这样的表示:options(scipen=999) gg <- ggplot(df,aes(x=lunghezzaInput, y=tempi_k_random, colour = "blue")) + scale_color_discrete("Tempi") + geom_smooth(method="loess", se=F) + geom_smooth(aes(y=tempi_k_cinque,colour = "red"), method = "loess", se=...
如何在ggplot的scale_x_discrete中指定频率或断点?一种选择是使用lambda函数只为每个第四个类别添加一个...