我想制作一个数据框,其中包含用于ggplot从GGally上面生成的汇总数据(变量和相关值)。
library(ggplot2)
library(GGally)
data(flea)
p <- ggpairs(flea, columns = 2:4)
p.2.df <- ggplot_build(p)
Error in UseMethod("ggplot_build") :
no applicable method for 'ggplot_build' applied to an object of class "c('gg', 'ggmatrix')"
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这ggplot_build不起作用。请问有什么帮助吗?
size vector cannot be allocated我对函数中反复出现的问题感到惊讶geom_raster。这个问题发生在小数据集上,在我的例子中,有 1559 个观察值。我尝试这样做:
# Read the raster in data frame format
ras_df<-read.csv("https://raw.githubusercontent.com/Leprechault/trash/main/myraster_df.csv")
str(ras_df)
#'data.frame': 1559 obs. of 3 variables:
# $ cc : num 65 85.6 82.7 85.6 89.4 ...
# $ longitude: num -50.6 -50.6 -50.6 -50.6 -50.6 ...
# $ latitude : num -24.2 -24.2 -24.2 -24.2 -24.2 ...
# Representation
ggplot() +
geom_raster(data = ras_df , aes(x = longitude, y = latitude, fill = cc)) +
scale_fill_gradientn(name="Canopy cover",colours = rev(terrain.colors(100)))+ …Run Code Online (Sandbox Code Playgroud) 我尝试了解组之间的PERMANOVA假设multivariate spread类似于中的方差同质性univariate ANOVA,为此,我制作了R代码,但找不到此结果,为什么?
我的代码:
library(vegan)
# Four similar populations:
spdf <- matrix(NA, 60, 4, dimnames =
list(1:60, c("sp1", "sp2", "sp3", "sp4")))
spdf <- as.data.frame(spdf)
eff <- sort(rep(1:6, 10))
spdf$sp1 = eff + rnorm(60, 0, 0.25)
spdf$sp2 = eff + rnorm(60, 0, 0.25)
spdf$sp3 = eff + rnorm(60, 0, 0.25)
spdf$sp4 = eff + rnorm(60, 0, 0.25)
#3 Treatment
treat <- gl(3, 20, labels = paste("t", 1:3, sep=""))
# distance matrix
envdist <- vegdist(spdf, method="euclidean") …Run Code Online (Sandbox Code Playgroud)