【发布时间】:2021-06-26 12:59:37
【问题描述】:
我有许多数据框 school_skill_score_ff,其中包含三列“Skill_full_form”、“2020”、“2021”。我正在尝试为条形图创建管道。我的代码在这里。
school_bar<-school_skill_score_ff%>%
e_chart(Skill_full_form,backgroundColor='#0d1117',center=c('50%','35%'))%>%
e_bar(`2021`,label=list(show=TRUE,color='#fff',position='top'))%>%
e_bar(`2020`,label=list(show=TRUE,color='#fff',position='top'))%>%
#e_tooltip(trigger = "axis")%>%
e_tooltip(trigger = "axis",axisPointer=list(type='shadow'))%>%
#e_title("Skills Score") %>%
e_theme("westeros")%>%
e_toolbox_feature("dataZoom")%>%
e_animation(duration = 2000)%>%
e_hide_grid_lines('x')%>%
e_y_axis(splitLine=list(lineStyle=list(color='#0f375f')),axisLabel=list(fontSize=10,color='#fff',fontWeight='normal'),name='Skill Score',nameLocation='middle',nameGap=30,nameColor='#fff')%>%
e_x_axis(axisLabel=list(rotate=16,fontSize=10,color='#fff',fontWeight='normal'))%>%
#e_axis_labels(x='Skill Name', y = "Skill Score")%>%
e_y_axis(name='Skill Score',nameLocation='middle',nameGap=38,splitLine=list(lineStyle=list(color='#0f375f')))%>%
#e_title("School Skill Score",top='0%',left='45%',textStyle=list(color='#fff'))%>%
e_legend(top='8%',left='46%',textStyle=list(color='#fff'))%>%
#e_title("School Skill Graph",textStyle=list(color='#fff',fontWeight='normal'),left='center',top='5%') %>%
#e_x_axis(axisLabel=list(rotate=17,fontSize=12))%>%
e_grid(show=TRUE,top='4%',width='90%',left='5%')#,name='Skill Names',nameGap=60,nameLocation='middle')
我的问题是我直接从 excel 文件中获取文件,并且许多文件没有“2020”列。这会产生错误。我想自动处理此错误,以便在第二列不存在时至少出现一列的图形。我正在使用 echarts4r 库。
【问题讨论】: