![](/img/trans.png)
[英]R Highcharter tickmarkPlacement with hchart() function
[英]How to change chart height in hchart() function in R (highcharter package) without using pipe operator?
我構建了一個Shiny應用程序,在該應用程序中,我從hist()
和density()
對象創建了一些繪圖,它們都以列表的形式保存到另一個腳本文件的.RDS文件中。 因此,在閃亮的情況下,我僅讀取.RDS並進行繪制。
現在一切正常,但是我沒有找到如何使用hchart()
函數更改highchart圖的高度。 在我的代碼,它建的方式,我不能管“%>%”的工作,怎么一回事,因為我使用hchart
一個內部purrr::map()
函數。
為了更好地解釋,我創建了一個小示例,如下。
# Example of how the objects are structured
list <-
list(df1 = list(Sepal.Length = hist(iris$Sepal.Length, plot = FALSE)),
df2 = list(Sepal.Length = density(iris$Sepal.Length)))
# Example of a plot built with hchart function
list[['df2']]['Sepal.Length'] %>%
purrr::map(hchart, showInLegend = FALSE)
# Example of what does not work
list[['df2']]['Sepal.Length'] %>%
purrr::map(hchart, showInLegend = FALSE, height = 200)
實際上,我還想更改圖表的更多選項,例如顏色。 但是我找不到這種解決方案的方法。
提前致謝。
Wlademir。
我可以看到2種主要方法來完成所需的工作(不確定為什么不能使用管道):
創建一個函數來處理所有數據,並在該函數內添加選項:
get_hc <- function(d) {
hchart(d, showInLegend = FALSE) %>%
hc_size(heigth = 200) %>%
hc_title(text = "Purrr rocks")
}
然后:
list_of_charts <- list[['df2']]['Sepal.Length'] %>%
purrr::map(get_hc)
您可以依次使用purrr::map
:
list_of_charts <- list[['df2']]['Sepal.Length'] %>%
purrr::map(hchart, showInLegend = FALSE)
# change heigth
list_of_charts <- purrr::map(list_of_charts, hc_size, height = 200)
# change title
list_of_charts <- purrr::map(list_of_charts, hc_title. text = "Purrr rocks")
或者,您可以依次使用purrr::map
/ %>%
組合:
list_of_charts <- list[['df2']]['Sepal.Length'] %>%
purrr::map(hchart, showInLegend = FALSE) %>%
purrr::map(hc_size, height = 200) %>%
purrr::map(hc_title, text = "Purrr rocks")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.