JAVA定义一个多边形类_如何在每个数据类别中绘制多个多边形?
一些代碼在SIBRE的捆綁演示數(shù)據(jù)集上執(zhí)行此操作 .
在這個例子中,我們嘗試使用ggplot2創(chuàng)建后橢圓的多個樣本的一些圖 .
library(SIBER)
library(ggplot2)
library(dplyr)
library(ellipse)
使基本SIBER模型適合與包捆綁在一起的示例數(shù)據(jù) .
# 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"
)
現(xiàn)在我們想要從這些分布中創(chuàng)建一些樣本橢圓的圖 . 我們需要為每個組創(chuàng)建所有省略號的data.frame對象 . 在這個例子中,我們簡單地將第10個后部繪制假設(shè)它們彼此獨立,但如果您愿意,可以隨機抽取樣本 .
# 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
現(xiàn)在來創(chuàng)建情節(jié) . 首先根據(jù)需要繪制所有原始數(shù)據(jù) .
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)
現(xiàn)在我們可以嘗試按組添加頂部和刻面上的后橢圓
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)
總結(jié)
以上是生活随笔為你收集整理的JAVA定义一个多边形类_如何在每个数据类别中绘制多个多边形?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: layui select 修改_layu
- 下一篇: 海盐味的夏天的情侣名是什么?