Open WangJL2021 opened 3 years ago
arr=c(0, 0, 0, 1, 1)
library(ggplot2)
draw6=function(bw=0.2, isTrim=T){
ggplot(data.frame(group=1, value=arr), aes(x=group, y=value)) +
geom_violin(bw=bw, trim=isTrim)+
theme_bw(base_size = 12)+
ggtitle( sprintf("bw=%s, trim=%s", bw, isTrim) )+
theme(
title = element_text(size=8)
)
}
g1=draw6(0.1, F); g1
g2=draw6(0.01, F); g2
g3=draw6(0.1, T); g3
g4=draw6(0.01, T); g4
library(gridExtra)
pdf("a6.pdf", width=4, height=4)
grid.arrange( g1, g2, g3, g4, nrow=2)
dev.off()
# same as in 5, but on Y axis.
1. Generate dataset
Density plot will overflow borders for smoothness, especially when extrema locate as borders, as demonstrated in this case.
2. Ggplot will cut the density curve at the border line.
3. Peaks sharpen as the bandwidth decreases
By default, bandwidth will change according to the dataset.
4. Cut the margin between y-axis to figure by setting xaxs ="i"
5. try ggplot2
== end ==