#将基础图赋值为p,两边加上括号,表示赋值的同时也直接print图片显示。
p1 <- ggplot(data)+
geom_line(aes(x = reorder(year, year), #见下面注释
y = WoS, group = 1),
linetype = 1, cex = 0.8, color = "orange") +
geom_point(
aes(x = reorder(year, year), #见下面注释
y = WoS),
color = "orange2", size = 2, alpha = 0.8
) +
labs(x=NULL,y='国际期刊发文量') + #自定义x、y轴、标题内容
theme_test(base_size = 10)+ #主题基本大小
theme(axis.text.x = element_text(angle = 45,hjust = 1),
axis.text = element_text(color = 'black',face = 'bold'),
plot.margin = margin(1,0.5,0.5,2.5,'cm'),
panel.border = element_rect(size = 1),
axis.title = element_text(face = 'bold', family = "Kai"),
plot.title = element_text(face = 'bold',
size=13,hjust = 0.5))
p1
(p2 <- p1+
scale_y_continuous(expand = c(0,0),limits = c(0,2000),
sec.axis = sec_axis(~./10,
name = 'CNKI',
breaks = seq(0,200,20)))+
geom_line(aes(x= reorder(year, year),
y= CNKI*10,
group=1),
linetype=1,cex=0.8, color = "darkolivegreen3")+
geom_point(aes(x= reorder(year, year),
y= CNKI*10),
color='#589c47',size=2, alpha = 0.7)
)
# 添加图例
#先定义一个用来画框的数据框:
df <- data.frame(a=c(6,6,27,27),
b=c(2000,1900,1900,2000))
(p3 <- p2+
annotate('segment',x=8,xend = 12, y=1950,yend = 1950,
linetype=1,cex=0.8,color = "orange")+
annotate('text',x=10,y=1950,label='•',
size=10,color='orange2', alpha = 0.8)+
annotate('text',x=14,y=1950,label='WoS',
fontface='bold',size=4)+
annotate('segment',x=17,xend = 21,y=1950,yend = 1950,
linetype=1,cex=0.8,color="darkolivegreen3")+
annotate('text',x=19,y=1950,label='•',
size=10,color='#589c47')+
annotate('text',x=23,y=1950,label='WoS',
fontface='bold',size=4.5)+
geom_line(data = df,aes(a,b),cex=0.5))
df <- data.frame(x = LETTERS[1:10],
y = 1:10)
ggplot() +
geom_star(data = df, aes(x = x, y = y, starshape = x, fill = x), size = 5) +
theme_bw()