更改桑基图中的字体

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

我正在使用“sfo”包来准备桑基图。下面,您可以看到我的代码和数据

library(sfo)
library(dplyr, warn = FALSE)
library(plotly)


sfo_passengers %>% 
  filter(operating_airline == "United Airlines",
         activity_period >= 201901 & activity_period < 202001) %>%
  mutate(terminal = ifelse(terminal == "International", "international", terminal)) %>%
  group_by(operating_airline,activity_type_code, geo_summary, geo_region,  terminal) %>%
  summarise(total = sum(passenger_count), .groups = "drop") %>%
  sankey_ly(cat_cols = c("operating_airline", "terminal","geo_summary", "geo_region", "activity_type_code"), 
            num_col = "total",
            title = "Dist. of United Airlines Passengers at SFO During 2019")

p <- plotly::last_plot()

plotly::add_annotations(p, c("Terminals", "Domestic/Int"), x = c(0.2, 0.5), y = c(1, 1), showarrow = FALSE)

现在我想改变这个图中的两件事。首先是更改字体并使用粗体 Arial 字体,其次是将此图表导出为 PDF。有人可以帮忙解决这个问题吗?

r plotly sankey-diagram
1个回答
0
投票

使用

plotly::layout
,您可以修改绘图的各种属性,例如字体系列。
要将绘图保存为 PDF 格式,可以使用
webshot
包。

library(sfo)
library(dplyr, warn = FALSE)
library(plotly)


p <- sfo_passengers %>% 
  filter(operating_airline == "United Airlines",
         activity_period >= 201901 & activity_period < 202001) %>%
  mutate(terminal = ifelse(terminal == "International", "international", terminal)) %>%
  group_by(operating_airline,activity_type_code, geo_summary, geo_region,  terminal) %>%
  summarise(total = sum(passenger_count), .groups = "drop") %>%
  sankey_ly(cat_cols = c("operating_airline", "terminal","geo_summary", "geo_region", "activity_type_code"), 
            num_col = "total",
            title = "Dist. of United Airlines Passengers at SFO During 2019") %>%
  add_annotations(c("Terminals", "Domestic/Int"), x = c(0.2, 0.5), y = c(1, 1), showarrow = FALSE) %>%
  layout(font=list(family="Arial", size=30, color="red"), margin=list(t=100))


library(htmlwidgets)
saveWidget(p, "plotly_plot.html", selfcontained = TRUE)

library(webshot)
webshot::install_phantomjs()
webshot("plotly_plot.html", "plotly_plot.pdf", vwidth = 2*992, vheight = 2*544, zoom=.65,
cliprect = "viewport")

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