文章转载自“医学统计与R语言”公众号,文章链接为:文章链接
输入1
library(ggplot2)
library(ggthemes)
library(ggsci)
library(rio)
percentbar <- import("percentbar.xlsx")
percentbar
输出1
year government society Individual
1 2009 21.12 39.34 39.54
2 2010 23.21 38.54 38.25
3 2011 23.14 38.77 38.09
4 2012 22.20 44.65 33.15
5 2013 22.96 43.85 33.19
6 2014 22.45 46.06 31.49
7 2015 22.22 48.29 29.49
8 2016 21.68 50.33 27.99
9 2017 21.18 51.83 26.99
输入2
percentbar <- gather(percentbar,key=subject,value=TEH,-year)
percentbar$subject <- factor(percentbar$subject,levels = c("Individual","society","government"))
ggplot(percentbar,aes(x=year,y=TEH,fill=subject))+geom_bar(stat="identity")+
geom_text(aes(label = paste(TEH,"%")), size=5,col="white",
position=position_stack(vjust = 0.5)) +theme_stata()+
theme(legend.position="bottom", legend.text = element_text(face="bold",size=12),
legend.title = element_blank())+ scale_x_continuous(breaks=seq(2009,2017,1))+
scale_y_continuous(labels = paste(c(0,25,50,75,100),'%'))+labs(x="Year", y="Total Expenditure on Health")+
theme(axis.text= element_text(face="bold",size=12),axis.title =element_text(face="bold",size=14) )+
theme(axis.line = element_line(size=1.2, colour = "black"),
panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.border = element_blank(), panel.background = element_blank())+
scale_fill_lancet()
输出2
输入3
radar <- import("radar.xlsx")
radar
输出3
指标 浙江 江苏 广东 全国
1 每千人执业(助理)医师数 3.33 2.90 2.44 2.59
2 每千人注册护士数 3.51 3.23 2.95 2.94
3 每千人口床位数 5.79 6.10 4.56 6.03
4 卫生总费用占GDP比例(%) 5.46 4.30 5.15 6.36
5 居民年平均就诊次数 10.94 7.38 7.45 5.96
6 年住院率(%) 17.80 18.00 15.10 18.30
输入4
install.packages("radarchart")
library(radarchart)
chartJSRadar(radar,labelSize=20, scaleStartValue=0,responsive=T,
polyAlpha=0,lineAlpha=1, addDots=T,
scaleStepWidth = 4,maxScale = 20,
showLegend = T,width = "450", height = "300")
输出4
输入5
install.packages("fmsb")
library(fmsb)
radar1 <- as.data.frame(t(radar[,-1]));radar1
colnames(radar1) <- radar$指标
radar2<- rbind(c(4,4,7,7,11,20) , rep(0,6) , radar1);radar2
library(RColorBrewer)
colors_border<- brewer.pal(4, "Dark2")
library(scales)
colors_in <- alpha(colors_border,0.1)
radarchart(radar2,axistype =2,seg=5,pty=2,plty=2,plwd=2,cglty=1,
cglwd=1,cglcol="gray",
axislabcol="blue", centerzero=T,vlcex=1.3,pcol=colors_border,pfcol=colors_in)
legend(x=1.2 , y=1.4,legend = rownames(radar2[-c(1,2),]), bty = "n",
pch=2, col=colors_border , text.col = "black", cex=1.5, pt.cex=1.5)
输出5
The data frame to be used to draw radarchart. If maxmin is TRUE, this must include maximum values as row 1 and minimum values as row 2 for each variables, and actual data should be given as row 3 and lower rows. The number of columns (variables) must be more than 2.