如何解决减少/删除 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
这是输出
这是所需的输出
感谢您的帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。