ggplot()+ geom_histogram(binwidth = 200,data=data,aes(x=SII,y=..count..),alpha = 0.8,colour="gold3",fill="gold3")+ scale_y_continuous(sec.axis = sec_axis(~./80, name = "HR (95%CI) for 2-year all-cause mortality"))+ geom_line(data=HR, aes(SII,yhat*80), linetype="solid",size=1,alpha = 0.7,colour="steelblue1")+ geom_ribbon(data=HR, aes(SII,ymin = lower*80, ymax = upper*80), alpha = 0.1,fill="blue")+ theme_classic()+ geom_hline(yintercept=1*80, linetype=2,size=1)+ geom_vline(xintercept=570,size=1,linetype=2,color = '#d40e8c')+ geom_vline(xintercept=1010,size=1,linetype=2,color = '#d40e8c')+#查表HR=1对应的age labs(x="Systemic immune-inflammation index", y="Count")+ xlim(0,3500)+ labs(title = " ")+ theme(plot.title = element_text(hjust = 0.5))
时间: 2024-04-20 18:27:30 浏览: 204
这是一段 R 代码,使用 ggplot2 包进行数据可视化。首先使用 geom_histogram 函数绘制直方图,binwidth 参数设置直方图的宽度,data 参数指定数据集,aes 函数设置 x 轴为 SII,y 轴为计数,alpha 参数设置透明度,colour 参数设置边框颜色,fill 参数设置填充颜色。然后使用 scale_y_continuous 函数设置 y 轴的第二个坐标轴,sec.axis 参数指定第二个坐标轴,~./80 表示原坐标轴除以 80,name 参数设置坐标轴名称。接着使用 geom_line 函数绘制折线图,data 参数指定数据集,aes 函数设置 x 轴为 SII,y 轴为 yhat*80,linetype 参数设置线型,size 参数设置线宽,alpha 参数设置透明度,colour 参数设置颜色。使用 geom_ribbon 函数绘制带状图,data 参数指定数据集,aes 函数设置 x 轴为 SII,ymin 参数设置下限,ymax 参数设置上限,alpha 参数设置透明度,fill 参数设置填充颜色。使用 theme_classic 函数设置主题样式,geom_hline 函数绘制水平参考线,yintercept 参数设置纵坐标值,linetype 参数设置线型,size 参数设置线宽度。geom_vline 函数绘制竖直参考线,xintercept 参数设置横坐标值,size 参数设置线宽度,linetype 参数设置线型,color 参数设置颜色。最后使用 labs 函数设置图例和坐标轴标签,xlim 函数设置 x 轴的最小值和最大值,labs 函数设置标题,theme 函数设置主题。
阅读全文
相关推荐


















