
虽然我找到了一种方法来为表添加滚动条/滚动框(通过使用Kable)和代码块输出,但我无法为绘图添加滚动条.大多数情节并不大,也不是问题,但是对于一个/两个情节,有很多类别,我需要绘图在浏览器窗口大小改变时不调整大小或使整个页面的宽度变大.理想情况下,如果可能,它应该具有特定的大小和固定宽度的滚动框.
这是我想要做的那种情节的一个例子.欢迎任何建议!
---Title: "Add horizontal scrol"author: "KTy"date: "9/21/2018"output: HTML_document---```{r setup,include=FALSE}knitr::opts_chunk$set(echo = TRUE)require(ggplot2)```## R Markdown### Want to add horizontal scroll bar around a plot```{r rnorm_Box_violin}set.seed(2300)xdf1 <- data.frame( var1 = rnorm( 10000,mean = 5000,sd = 10),str1 = rep("a0",10000) )for ( x in 10:50 ){ n <- sample(x = c(10,0.1),size = 1) xdf2 <- data.frame( var1 = rnorm( x*n*1000,mean = 5000+(x/2),str1 = rep(paste0("a",x),x*n*1000)) xdf1 <- rbind(xdf1,xdf2) }plot1 <- ggplot( data = xdf1,aes( x = str1,y = var1 )) + geom_violin(fill='grey90',scale = 'count',colour = 'grey70') + geom_Boxplot( wIDth = 0.2,Alpha = 0.1,colour = 'grey30')+ theme_bw()+ theme(axis.text.x = element_text(angle = 45,hjust = 1,vjust = 1))```Produces this plot:```{r plot_it,echo = FALSE,wIDth = 20,height = 7}plot1``` 我在Mac上使用RStudio.我希望我所要求的是有意义的,如果有任何不清楚的地方请留下评论,我可以尝试进一步解释.干杯,谢谢!
解决方法 您可以为编织器文档添加自定义CSS:... plot1 <- ggplot( data = xdf1,y = var1 )) + geom_violin(fill='grey90',colour = 'grey70') + geom_Boxplot( wIDth = 1,colour = 'grey30')+ theme_bw()+ theme(axis.text.x = element_text(angle = 45,vjust = 1))```<style> .superbigimage{ overflow-x:scroll; white-space: nowrap; } .superbigimage img{ max-wIDth: none; }</style>This produces the plot with a special CSS class<div >```{r plot_it,fig.wIDth=20,fig.height=3}plot1```</div>This produces the plot with the default settings```{r plot_it2,fig.height=3}plot1``` 图片为懒惰:
总结以上是内存溢出为你收集整理的如何在RMarkdown html中为ggplot图添加水平滚动条全部内容,希望文章能够帮你解决如何在RMarkdown html中为ggplot图添加水平滚动条所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)