使用 fviz_nbclust 时增大字体大小?

Increase font size while using fviz_nbclust?

我正在尝试增加我正在使用 fviz_nbclust 制作的绘图的 font/label 大小。我尝试查找 "fviz_nbclust"、"size"、"font"、"increase" 的各种组合,但没有找到任何结果。

我在 this post that worked when I was doing just plot() that it worked, but can't just be used with fviz_nbclust. I also checked the documentation for the package factoextra (here) 上看到了一条建议,但在第 49/50 页上并没有真正看到任何我认为可能有帮助的内容。

这是我的代码:

set.seed(123)
wss <- function(k) {
       kmeans(datT, k, nstart = 10)$tot.withinss
       }
k.values <- 1:15
wss_values <- map_dbl(k.values, wss)

pdf("within_clus_sum1.pdf",width = 11, height = 8) 
plot(k.values, wss_values,
       type="b", pch = 19, frame = FALSE, 
       xlab="Number of clusters K",
       ylab="Total within-clusters sum of squares",
       cex.lab=1.5, cex.axis=1.5, cex.main=1.5, cex.sub=1.5)

dev.off() 

pdf("within_clus_sum2.pdf",width = 11, height = 8) 
fviz_nbclust(datT, kmeans, method = "wss")
dev.off() 

如您所见,我只是想了解使用 Elbow 方法确定的最佳簇数。

我希望做的是增加使用 fviz_nbclust 生成的图中的标题、标签和刻度线大小,因为我在其中包含一个 write-up,如果我把连续两个或三个地块,它们几乎难以辨认。任何人都可以提供任何帮助,我们将不胜感激。

factoextra 包使用 ggplot2 生成图表。这意味着您可以使用 ggplot2 主题更改绘图的外观。例如:

elbow.plot <- fviz_nbclust(datT, kmeans, method = "wss", k.max = 10, verbose = F, nboot = 100)
# change size and color of title and x axis labels
elbow.plot + theme(axis.text.x = element_text(size = 15, color = "red"), title = element_text(size = 15, color = "blue")

您可以了解更多关于 ggplot2 的信息,例如 here

如果你想改变线条的颜色和大小,我意识到这有点棘手,因为实际上 fviz_nbclust 函数调用一个 ggpubr 函数,它是 ggplot2 的包装器(就这么简单) .唯一可以轻松更改的参数是线条颜色:

fviz_nbclust(datT, kmeans, method = "wss", k.max = 10, verbose = F, nboot = 100, linecolor = "red")

要更改其他参数,您可以执行以下操作:

fviz_nbclust(datT, kmeans, method = "wss", k.max = 10, verbose = F, nboot = 100)  + 
theme(axis.text.x = element_text(size = 15))  + 
geom_line(aes(group = 1), color = "red", linetype = "dashed",size = 3) + 
geom_point(group = 1, size = 5, color = "blue")

这基本上是在顶部再次绘制绘图,这不是最佳选择,但作为快速修复效果很好。