JAVA定义一个多边形类_如何在每个数据类别中绘制多个多边形?

一些代码在SIBRE的捆绑演示数据集上执行此操作 .

在这个例子中,我们尝试使用ggplot2创建后椭圆的多个样本的一些图 .

library(SIBER)

library(ggplot2)

library(dplyr)

library(ellipse)

使基本SIBER模型适合与包捆绑在一起的示例数据 .

# load in the included demonstration dataset

data("demo.siber.data")

#

# create the siber object

siber.example

# Calculate summary statistics for each group: TA, SEA and SEAc

group.ML

# options for running jags

parms

parms$n.iter

parms$n.burnin

parms$n.thin

parms$n.chains

# define the priors

priors

priors$R

priors$k

priors$tau.mu

# fit the ellipses which uses an Inverse Wishart prior

# on the covariance matrix Sigma, and a vague normal prior on the

# means. Fitting is via the JAGS method.

ellipses.posterior

# The posterior estimates of the ellipses for each group can be used to

# calculate the SEA.B for each group.

SEA.B

siberDensityPlot(SEA.B, xticklabels = colnames(group.ML),

xlab = c("Community | Group"),

ylab = expression("Standard Ellipse Area " ('\u2030' ^2) ),

bty = "L",

las = 1,

main = "SIBER ellipses on each group"

)

现在我们想要从这些分布中创建一些样本椭圆的图 . 我们需要为每个组创建所有省略号的data.frame对象 . 在这个例子中,我们简单地将第10个后部绘制假设它们彼此独立,但如果您愿意,可以随机抽取样本 .

# how many of the posterior draws do you want?

n.posts

# decide how big an ellipse you want to draw

p.ell

# for a standard ellipse use

# p.ell

# a list to store the results

all_ellipses

# loop over groups

for (i in 1:length(ellipses.posterior)){

# a dummy variable to build in the loop

ell

post.id

for ( j in 1:n.posts){

# covariance matrix

Sigma

# mean

mu

# ellipse points

out

ell

post.id

}

ell

ell$rep

all_ellipses[[i]]

}

ellipse_df

# now we need the group and community names

# extract them from the ellipses.posterior list

group_comm_names

# split them and conver to a matrix, NB byrow = T

split_group_comm

nrow(ellipse_df), 2, byrow = TRUE)

ellipse_df$community

ellipse_df$group

ellipse_df

现在来创建情节 . 首先根据需要绘制所有原始数据 .

first.plot

geom_point(aes(color = factor(group):factor(community)), size = 2)+

ylab(expression(paste(delta^{15}, "N (\u2030)")))+

xlab(expression(paste(delta^{13}, "C (\u2030)"))) +

theme(text = element_text(size=15))

print(first.plot)

现在我们可以尝试按组添加顶部和刻面上的后椭圆

second.plot

print(second.plot)

# rename columns of ellipse_df to match the aesthetics

third.plot

geom_polygon(data = ellipse_df,

mapping = aes(iso1, iso2,

group = rep,

color = factor(group):factor(community),

fill = NULL),

fill = NA,

alpha = 0.2)

print(third.plot)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值