- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用 factomineR
和 factoextra
包制作 pca。
我的数据 iris 代码示例:
library(FactoMineR)
library(factoextra)
data(iris)
res.pca<-PCA(iris , scale.unit=TRUE, ncp=2, quali.sup=c(5), graph = FALSE)
fviz_pca_biplot(res.pca, label="var", habillage=5,
addEllipses=TRUE) + theme_minimal()
我想改变椭圆周围线条的宽度,变量的宽度也是如此。我尝试了几种方法,但我不知道如何做我想做的事。
有什么想法吗?
最佳答案
我会创建所需函数的副本并更改其中的代码。具体来说,要增加椭圆的宽度,您可以在调用 ggplot2::stat_ellipse
命令时添加 size=..
。
my_fviz_pca_biplot <- function (X, axes = c(1, 2), geom = c("point", "text"), label = "all",
invisible = "none", labelsize = 4, pointsize = 2, habillage = "none",
addEllipses = FALSE, ellipse.level = 0.95, col.ind = "black",
col.ind.sup = "blue", alpha.ind = 1, col.var = "steelblue",
alpha.var = 1, col.quanti.sup = "blue", col.circle = "grey70",
repel = FALSE, axes.linetype = "dashed", select.var = list(name = NULL,
cos2 = NULL, contrib = NULL), select.ind = list(name = NULL,
cos2 = NULL, contrib = NULL), title = "Biplot of variables and individuals",
jitter = list(what = "label", width = NULL, height = NULL),
...)
{
if (is.null(jitter$what))
jitter$what <- "label"
if (length(axes) != 2)
stop("axes should be of length 2")
scale.unit <- .get_scale_unit(X)
var <- facto_summarize(X, element = "var", result = c("coord",
"contrib", "cos2"), axes = axes)
colnames(var)[2:3] <- c("x", "y")
var.all <- var
if (!is.null(select.var))
var <- .select(var, select.var)
lab <- .label(label)
hide <- .hide(invisible)
alpha.limits <- NULL
if (alpha.var %in% c("cos2", "contrib", "coord", "x", "y"))
alpha.limits = range(var.all[, alpha.var])
pca.ind <- get_pca_ind(X)
ind <- data.frame(pca.ind$coord[, axes, drop = FALSE])
colnames(ind) <- c("x", "y")
r <- min((max(ind[, "x"]) - min(ind[, "x"])/(max(var[, "x"]) -
min(var[, "x"]))), (max(ind[, "y"]) - min(ind[, "y"])/(max(var[,
"y"]) - min(var[, "y"]))))
var[, c("x", "y")] <- var[, c("x", "y")] * r * 0.7
p <- my_fviz_pca_ind(X, axes = axes, geom = geom, repel = repel,
label = label, invisible = invisible, labelsize = labelsize,
pointsize = pointsize, axes.linetype = axes.linetype,
col.ind = col.ind, col.ind.sup = col.ind.sup, alpha.ind = alpha.ind,
habillage = habillage, addEllipses = addEllipses, ellipse.level = ellipse.level,
select.ind = select.ind, jitter = jitter)
if (!hide$var) {
p <- .ggscatter(p = p, data = var, x = "x", y = "y",
col = col.var, alpha = alpha.var, alpha.limits = alpha.limits,
geom = c("arrow", "text"), repel = repel, lab = lab$var,
labelsize = labelsize, jitter = jitter)
}
if (inherits(X, "PCA") & !hide$quanti) {
quanti_sup <- .get_supp(X, element = "quanti", axes = axes,
select = select.var)
if (!is.null(quanti_sup))
colnames(quanti_sup)[2:3] <- c("x", "y")
if (!is.null(quanti_sup)) {
p <- fviz_add(p, df = quanti_sup[, 2:3, drop = FALSE] *
r * 0.7, geom = c("arrow", "text"), color = col.quanti.sup,
linetype = 2, labelsize = labelsize, addlabel = (lab$quanti),
jitter = jitter)
}
}
title2 <- title
p + labs(title = title2)
}
environment(my_fviz_pca_biplot) <- environment(fviz_pca_biplot)
my_fviz_pca_ind <- function (X, axes = c(1, 2), geom = c("point", "text"), repel = FALSE,
label = "all", invisible = "none", labelsize = 4, pointsize = 2,
habillage = "none", addEllipses = FALSE, ellipse.level = 0.95,
ellipse.type = "norm", ellipse.alpha = 0.1, col.ind = "black",
col.ind.sup = "blue", alpha.ind = 1, select.ind = list(name = NULL,
cos2 = NULL, contrib = NULL), jitter = list(what = "label",
width = NULL, height = NULL), title = "Individuals factor map - PCA",
axes.linetype = "dashed", ...)
{
if (length(intersect(geom, c("point", "text", "arrow"))) ==
0)
stop("The specified value(s) for the argument geom are not allowed ")
if (length(axes) != 2)
stop("axes should be of length 2")
if (is.null(jitter$what))
jitter$what <- "label"
ind <- facto_summarize(X, element = "ind", result = c("coord",
"contrib", "cos2"), axes = axes)
colnames(ind)[2:3] <- c("x", "y")
ind.all <- ind
if (!is.null(select.ind))
ind <- .select(ind, select.ind)
lab <- .label(label)
hide <- .hide(invisible)
alpha.limits <- NULL
if (alpha.ind %in% c("cos2", "contrib", "coord", "x", "y"))
alpha.limits = range(ind.all[, alpha.ind])
if (habillage[1] == "none") {
p <- ggplot()
if (hide$ind)
p <- ggplot() + geom_blank(data = ind, aes_string("x",
"y"))
else p <- .ggscatter(data = ind, x = "x", y = "y", col = col.ind,
alpha = alpha.ind, repel = repel, alpha.limits = alpha.limits,
shape = 19, geom = geom, lab = lab$ind, labelsize = labelsize,
pointsize = pointsize, jitter = jitter)
}
else {
p <- ggplot()
if (hide$ind & hide$quali)
p <- ggplot() + geom_blank(data = ind, aes_string("x",
"y"))
if (inherits(X, "PCA") & length(habillage) == 1) {
data <- X$call$X
if (is.numeric(habillage))
name.quali <- colnames(data)[habillage]
else name.quali <- habillage
ind <- cbind.data.frame(data[rownames(ind), name.quali],
ind)
colnames(ind)[1] <- name.quali
ind[, 1] <- as.factor(ind[, 1])
}
else {
if (nrow(ind) != length(habillage))
stop("The number of active individuals used in the PCA is different ",
"from the length of the factor habillage. Please, remove the supplementary ",
"individuals in the variable habillage.")
name.quali <- "Groups"
ind <- cbind.data.frame(Groups = habillage, ind)
ind[, 1] <- as.factor(ind[, 1])
}
if (!hide$ind) {
label_coord <- ind
if (jitter$what %in% c("both", "b")) {
label_coord <- ind <- .jitter(ind, jitter)
}
else if (jitter$what %in% c("point", "p")) {
ind <- .jitter(ind, jitter)
}
else if (jitter$what %in% c("label", "l")) {
label_coord <- .jitter(label_coord, jitter)
}
if ("point" %in% geom)
p <- p + geom_point(data = ind, aes_string("x",
"y", color = name.quali, shape = name.quali),
size = pointsize)
if (lab$ind & "text" %in% geom) {
if (repel)
p <- p + ggrepel::geom_text_repel(data = label_coord,
aes_string("x", "y", label = "name", color = name.quali,
shape = name.quali), size = labelsize)
else p <- p + geom_text(data = label_coord, aes_string("x",
"y", label = "name", color = name.quali, shape = name.quali),
size = labelsize, vjust = -0.7)
}
}
if (!hide$quali) {
coord_quali.sup <- .get_coord_quali(ind$x, ind$y,
groups = ind[, 1])
coord_quali.sup <- cbind.data.frame(name = rownames(coord_quali.sup),
coord_quali.sup)
colnames(coord_quali.sup)[1] <- name.quali
coord_quali.sup[, 1] <- as.factor(coord_quali.sup[,
1])
if ("point" %in% geom) {
p <- p + geom_point(data = coord_quali.sup, aes_string("x",
"y", color = name.quali, shape = name.quali),
size = pointsize * 2)
}
if (lab$quali & "text" %in% geom) {
if (repel)
p <- p + ggrepel::geom_text_repel(data = coord_quali.sup,
aes_string("x", "y", color = name.quali),
label = rownames(coord_quali.sup), size = labelsize)
else p <- p + geom_text(data = coord_quali.sup,
aes_string("x", "y", color = name.quali), label = rownames(coord_quali.sup),
size = labelsize, vjust = -1)
}
}
if (addEllipses) {
if (ellipse.type == "convex") {
frame.data <- .cluster_chull(ind[, c("x", "y")],
ind[, name.quali])
colnames(frame.data)[which(colnames(frame.data) ==
"cluster")] <- name.quali
mapping = aes_string(x = "x", y = "y", colour = name.quali,
fill = name.quali, group = name.quali)
p <- p + ggplot2::geom_polygon(data = frame.data,
mapping = mapping, alpha = ellipse.alpha)
}
else if (ellipse.type %in% c("t", "norm", "euclid")) {
mapping = aes_string(x = "x", y = "y", colour = name.quali,
group = name.quali, fill = name.quali)
p <- p + ggplot2::stat_ellipse(mapping = mapping,
data = ind, level = ellipse.level, type = ellipse.type,
alpha = ellipse.alpha, geom = "polygon", size=5)
}
}
}
if (inherits(X, "PCA") & !hide$ind.sup) {
ind_sup <- .get_supp(X, element = "ind.sup", axes = axes,
select = select.ind)
if (!is.null(ind_sup))
colnames(ind_sup)[2:3] <- c("x", "y")
if (!is.null(ind_sup)) {
p <- fviz_add(p, df = ind_sup[, 2:3, drop = FALSE],
geom = geom, color = col.ind.sup, shape = 19,
pointsize = pointsize, labelsize = labelsize,
addlabel = (lab$ind.sup & "text" %in% geom),
jitter = jitter)
}
}
title2 <- title
p <- .fviz_finish(p, X, axes, axes.linetype) + labs(title = title2)
p
}
environment(my_fviz_pca_ind) <- environment(fviz_pca_ind)
然后使用新函数。
my_fviz_pca_biplot(res.pca, label="var", habillage=5,
addEllipses=TRUE) + theme_minimal()
关于r - Factoextra - 更改椭圆和变量的线宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37114192/
函数参数中或显示尺寸时(高度,宽度)的顺序是否有约定? 最佳答案 我不知道大量的语言,但我使用过的语言(宽度,高度)。它更适合沿着 (x, y) 坐标线。 关于language-agnostic -
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
有没有办法显示自定义宽度/高度的YouTube视频? 最佳答案 在YouTube网站上的this link中: You can resize the player by editing the obj
如何从此表单获取数据(数据的长表示): import pandas as pd df = pd.DataFrame({ 'c0': ['A','A','B'], 'c1': ['b',
我在让宽度为 900px 的页面在宽度低于 900px 的分辨率下看起来不错时遇到了一些麻烦。这包括智能手机等移动设备。看起来我在页面上放大了,但无法滚动或缩小。我的页面包装器被定义为以屏幕为中心。这
我有一个包含一个表的 div,它有另一个带有动态变化文本的 div。div 有样式 overflow: hidden; white-space: nowrap; text-overflow: elli
我一直在愚弄下面的html代码。我已将 div id ="mainWide"设置为 2500 像素的宽度,这比我的屏幕还宽,我希望在主浏览器窗口中有一个水平滚动条,而不是在 div block 本身中
当我的屏幕浏览器窗口在 992px-1199px 之间时,我的文章元素比它们的父 div (.wrapper) 更宽。所以在这个屏幕宽度下,面板重叠并且看起来不对。 在所有其他屏幕宽度下,我的代码都准
我在对齐某些行时遇到了一些问题。我正在显示一个占据视口(viewport) 100% 高度的部分。因此,当您在屏幕上查看此部分时,您只会看到此部分。 在这个部分中,我有一个标题和副标题。标题应显示在节
为什么表单输入字段比其父 div 宽?宽度应用于文本 div,但不应用于其中包含表单字段的 div。为什么会这样? See the livecode here. .parent { width:
我想让这个标题 100% 宽。我在 jsfiddle 上试过这个,但是左边和右边还有一些余量。 CSS: #header { background: url("../img/top-bg.png
我的页面宽度有问题。无论我尝试什么,它的左边或右边都有白边(默认情况下在右边,如果我使用 margin-right:0 则在左边)。如果我使用 margin:0 比它留在右边。尝试了我所知道的一切,但
我有一个带有背景图片的宽 div。 div 的宽度为 1100 像素,当浏览器窗口小于该宽度时,会出现滚动条。有什么办法可以避免滚动条吗?那不是任何黑客。现在我知道我可以把它放在 body image
我有一个您可以访问的应用程序 here .当您打开应用程序时,只需单击加号按钮,您就会看到一个带有搜索栏的模态窗口。 现在请执行这两个搜索: 搜索 1:AAA 搜索 2:AAE 您会看到,在 AAE
这个问题在这里已经有了答案: Does element width include padding? (5 个答案) 关闭 7 年前。 HTML CSS .wrap{widt
我正在尝试在工具栏中创建一个自定义显示,类似于 Xcode 工具栏中心的信息 Pane 。 我们如何创建一个宽度超过 32 点的 NSToolbarItem? 框架始终将其限制为 32 点,即使最小和
我想将df1转换成df2 旧示例数据框 df1 df1 长),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/359
我正在使用 JavaScript 代码在 FireBase/FireStore 中上传图像。 核心功能已经可以运行,我可以上传,但我还需要在上传之前检查图像的大小。这就是我很乐意获得帮助的地方。 以下
如何在 Tkinter 中设置/更改 ttk.Separator 对象的长度/宽度? ttk.Separator(self, orient='horizontal').grid(c
我有一个简单的问题。为什么 a 不会自动调整其内容的大小?像这样: Test 返回 width:100%,尽管我希望“Test”这个词简单地居中。有什么想法吗? 最佳答案 您的问题与 HT
我是一名优秀的程序员,十分优秀!