Quantcast
Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

Christmas Tree with ggplot

0
0

Christmas Tree with ggplot
# create data x <- c(8,7,6,7,6,5,6,5,4,5,4,3,4,3,2,3,2,1,0.5,0.1)

dat1 <- data.frame(x1 = 1:length(x), x2 = x)

dat2 <- data.frame(x1 = 1:length(x), x2 = -x)

dat1$xvar <- dat2$xvar <- NA

dat1$yvar <- dat2$yvar <- NA

dat1$siz <- dat2$siz <- NA

dat1$col <- dat2$col dec_threshold){

dat1$xvar[row] <- row #sample(1:dat1$x1[row],1) dat1$yvar[row] <- sample(1:dat1$x2[row]-1,1) dat1$siz[row] <- runif(1,0.5,1.5) dat1$col[row] dec_threshold){ dat2$xvar[row] <- row #sample(1:dat2$x1[row],1) dat2$yvar[row] <- sample(1:dat2$x2[row],1) dat2$siz[row] <- runif(1,0.5,1.5) dat2$col[row] <- sample(1:5, 1)

}

}

# plot the christmas tree

ggplot() +

geom_bar(data = dat1, aes(x=x1, y=x2),stat = "identity", fill = '#31a354') +

geom_bar(data = dat2, aes(x=x1, y=x2),stat = "identity", fill = '#31a354') +

geom_point(data = dat1,aes(x = xvar, y = yvar, size = siz, colour = as.factor(col)) ) +

geom_point(data = dat2,aes(x = xvar, y = yvar, size = siz, colour = as.factor(col)) ) +

coord_flip() + theme_minimal()+ theme(legend.position="none",

axis.title.x=element_blank(),

axis.text.x=element_blank(),

axis.ticks.x=element_blank(),

axis.title.y=element_blank(),

axis.text.y=element_blank(),

axis.ticks.y=element_blank()) +

ggtitle('The Analytics Lab wishes you a Merry Christmas')


Viewing all articles
Browse latest Browse all 12749

Latest Images

Trending Articles





Latest Images