如何在RStudio Viewer中并排绘制Highcharter?

问题描述 投票:0回答:1

[我想尽可能地在RStudio Viewer中并排查看Highcharter图的确切输出,在此参考文献中完全显示了该内容:http://jkunst.com/highcharter/highcharts.html,因此让我像这样定义它以便简单使用]]

highcharter_all_plot <- function(){
  library(highcharter)
  library(dplyr)
  library(stringr)
  library(purrr)
  n <- 5
  set.seed(123)
  colors <- c("#d35400", "#2980b9", "#2ecc71", "#f1c40f", "#2c3e50", "#7f8c8d")
  colors2 <- c("#000004", "#3B0F70", "#8C2981", "#DE4968", "#FE9F6D", "#FCFDBF")

  df <- data.frame(x = seq_len(n) - 1) %>% 
    mutate(
      y = 10 + x + 10 * sin(x),
      y = round(y, 1),
      z = (x*y) - median(x*y),
      e = 10 * abs(rnorm(length(x))) + 2,
      e = round(e, 1),
      low = y - e,
      high = y + e,
      value = y,
      name = sample(fruit[str_length(fruit) <= 5], size = n),
      color = rep(colors, length.out = n),
      segmentColor = rep(colors2, length.out = n)
    )

  print(head(df))

  create_hc <- function(t) {
    dont_rm_high_and_low <- c("arearange", "areasplinerange",
                              "columnrange", "errorbar")
    is_polar <- str_detect(t, "polar")
    t <- str_replace(t, "polar", "")
    if(!t %in% dont_rm_high_and_low){
      df <- df %>% dplyr::select(-e, -low, -high)
    } 
    highchart() %>%
      hc_title(text = paste(ifelse(is_polar, "polar ", ""), t),
               style = list(fontSize = "15px")) %>% 
      hc_chart(type = t,
               polar = is_polar) %>% 
      hc_xAxis(categories = df$name) %>% 
      hc_add_series(df, name = "Fruit Consumption", showInLegend = FALSE) 
  }

  hcs <- c("line", "spline",  "area", "areaspline",
           "column", "bar", "waterfall" , "funnel", "pyramid",
           "pie" , "treemap", "scatter", "bubble",
           "arearange", "areasplinerange", "columnrange", "errorbar",
           "polygon", "polarline", "polarcolumn", "polarcolumnrange",
           "coloredarea", "coloredline")  %>% map(create_hc) 
  return(hcs)
}

x <- highcharter_all_plot()

#Then plot can be accessed in by calling x[[1]], x[[2]], x[[3]]..

据我对并排图的理解,我只知道其中两种方便的方法,它们是:

1)使用par(mfrow)

[par(mfrow=c(3,4))->(仅可应用于基本图)]

2)从gridExtra使用grid.arrange

library(gridExtra)
grid.arrange(x[[1]], x[[2]], x[[3]], x[[4]], nrow=2, ncol=2)

->(由于x不是ggplot类型而无法使用)

所以我想知道是否可以应用此方法?我是使用Highcharter的新手

我想尽可能地在RStudio Viewer中并排查看Highcharter图的精确输出,该参考文件中对此进行了精确显示:http://jkunst.com/highcharter/highcharts.html,所以让我定义一下...

r highcharts
1个回答
0
投票

[如果检查提供的Highcharter网站,您会发现这些图表不是使用R并排放置的,而是它们在单独的HTML容器中的呈现器,并通过引导程序(CSS)定位。因此,如果要在HTML环境中呈现图表,建议将每个图表呈现到单独的div中。

© www.soinside.com 2019 - 2024. All rights reserved.