减少/删除 R 可反应表中 htmlwidget ggplotly 对象的填充

问题描述

我在 R 中有一个可响应的表,其中包含一些嵌套的 ggplotly 对象。我希望减少间距/填充/行高。

代码如下:

df<-data.frame('Question Category'=letters[1:5),Favorable=c(37,36.2,34.8,34.6,34.9),Neutral=c(19.5,20.4,18.8,20.9),Not_Favorable = c(35.5,35.3,38.4,38.6,36.3),DNK=c(8,8,8))  


df2<-data.frame(df[,1])
df2[,2]<-c(1:nrow(df2))
names(df2)<-c('Question Category','Favorability')
plot_list<-list()
for(i in 1:nrow(df2)){
    subset_df <- df[i,3:ncol(df)]
    subset_df<-tibble::rownames_to_column(data.frame(t(subset_df)))
    subset_df[,3]<-df[i,1]
    names(subset_df)<-c('Category','score','Question_category')
    subset_df2<-subset_df %>% mutate(lab_ypos = cumsum(score)-0.5*score)

    g<-ggplotly(
      ggplot(subset_df2,aes(x=Question_category,y=score,fill=Category))+
      geom_bar(position='stack',stat='identity',width = 0.1)+ 
      coord_flip()+
      geom_text(aes(y=lab_ypos,label=score),color='white') +
        scale_y_continuous(expand = c(0,0)) + scale_x_discrete(expand = c(0,0))+
      theme(
      panel.background = element_blank(),panel.grid=element_blank(),axis.text = element_blank(),axis.title = element_blank(),legend.position = 'none',axis.ticks = element_blank()
            ),height=180)
 plot_list[[i]]<-g }
  
p<-reactable(df2,columns = list(
    Favorability = colDef(cell = function(value,index){
        plot_list[[index]]
     })
  ),bordered = TRUE,compact=TRUE)
  p

这是输出

enter image description here

这是所需的输出

enter image description here

感谢您的帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)