我正在尝试打印我的图表图表。
library(highcharter)
webshot::install_phantomjs()
colors_ <- colorize(1:6, c("#FFA500", "#000000"))
df <- data.frame(y = round(rnorm(5, 10, 2), digits = 1),
name = paste0("Name", c(1:5)),
color = colors_[1:5])
hc <- highchart() %>%
hc_chart(type = "column") %>%
hc_xAxis(categories = df$name) %>%
hc_add_series(
df,
dataLabels = list(
enabled = T,
shadow = F,
color = "black",
style = list(
textShadow = F,
textOutline = F,
fontWeight = 'normal',
opacity = 1
)
)
)
htmlwidgets::saveWidget(widget = hc, file = "hc.html")
webshot::webshot(url = "hc.html", file = "hc.png", delay = 1, zoom = 4, vheight = 500)
有标签,但非常透明。我尝试了不同的风格。没有成功。你能帮忙吗?
installed.packages():highcharter,htmlwidgets,webshot ...
而不是使用webshot,您应该考虑在不受此问题困扰的https://github.com/rstudio/webshot2上尝试webshot2。我已使用webshot2复制了您的方案,问题已解决,如下图所示。
注意:在尝试安装webshot2软件包之前,请不要忘记删除websot。为了删除它,请转到Rstudio右下角的Packages,搜索该包的名称,然后单击相邻的X图标将其删除,或者您可以通过Rstudio控制台以这种方式进行处理:
remove.packages("webshot", lib="~/R/win-library/3.6")
代码
library(highcharter)
library(webshot2)
colors_ <- colorize(1:6, c("#FFA500", "#000000"))
df <- data.frame(y = round(rnorm(5, 10, 2), digits = 1),
name = paste0("Name", c(1:5)),
color = colors_[1:5])
hc <- highchart() %>%
hc_chart(type = "column") %>%
hc_xAxis(categories = df$name) %>%
hc_add_series(
df,
dataLabels = list(
enabled = T,
shadow = F,
color = "black",
style = list(
textShadow = F,
textOutline = F,
fontWeight = 'normal',
opacity = 1
)
)
)
htmlwidgets::saveWidget(widget = hc, file = "hc.html")
webshot(url = "hc.html", file = "hc.png", delay = 1, zoom = 4, vheight = 500)
png文件(hc.png)