简体   繁体   English

在 Rmarkdown 中调整 highcharter 绘图尺寸

[英]Adjusting highcharter plot dimensions in Rmarkdown

I am using highcharter plots in Rmarkdown and I can't seem to adjust the height or the width (in RStudio).我在 Rmarkdown 中使用 highcharter 图,但我似乎无法调整高度或宽度(在 RStudio 中)。 Any suggestions?有什么建议吗? Details below:详情如下:

If I use the basic default code;如果我使用基本的默认代码;

```{r}
library(highcharter)

cars %>%
  hchart(.,"scatter",hcaes(x=speed,y=dist))
```

I get this:我明白了:

在此处输入图片说明

That doesn't change if I edit chunk options fig.height=4,fig.width=8 or if I change dimensions in the plot hc_chart(height=800,width=600) .如果我编辑块选项fig.height=4,fig.width=8或者如果我更改绘图中的尺寸hc_chart(height=800,width=600)这不会改变。

If I save the plot and print using a taglist, then it starts to become usable.如果我使用标签列表保存绘图并打印,那么它开始变得可用。

```{r}
h <- cars %>%
  hchart(.,"scatter",hcaes(x=speed,y=dist))

htmltools::tagList(list(h))
```

在此处输入图片说明

But, I still can't adjust dimensions using chunk options or using internal plot dimensions.但是,我仍然无法使用块选项或使用内部绘图尺寸来调整尺寸。

R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
highcharter_0.5.0

Use hc_size with height and width arguments:使用带有heightwidth参数的hc_size

{r}
h <- cars %>%
  hchart(.,"scatter",hcaes(x=speed,y=dist)) %>%
  hc_size(height=800,width=600)
h

Had the same problem and the comment from @jbkunst (kudos to them) to your question led me to this solution and it works - so I thought I'd post it as an answer.遇到了同样的问题,@jbkunst(对他们表示敬意)对您的问题的评论使我找到了这个解决方案并且它有效 - 所以我想我会把它作为答案发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM