[英]ggplotly theme inconsistency with ggplot2
嗨,我正在使用 ggplotly 添加與 plot 的交互性,我正在使用 ggplot2 為 shiny 儀表板制作。 plot 功能正常,只是看起來很傻,因為它沒有始終如一地使用我通常使用的主題( theme_jacob() )。 我知道在將 plotly 函數應用於 ggplot plot 時會出現很多問題,但我無法在線找到任何資源來解決我的特定問題。 我在下面粘貼了我的代碼。
theme_jacob <- function () {
theme_minimal(base_size=10, base_family="Gill Sans MT") %+replace%
theme(
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = 'floralwhite', color = 'floralwhite')
)
}
p <- df %>%
ggplot(aes(valence, energy, color = album_name, text = paste(track_name, '<br>', album_name, '<br>',
'Positivity ', round(valence, 2), '<br>',
'Energy ', round(energy, 2)))) +
geom_point(size = 2, alpha = 0.8) +
geom_hline(yintercept = 0.5) +
geom_vline(xintercept = 0.5) +
scale_x_continuous(limits = c(0, 1), breaks = seq(0, 1, .1)) +
scale_y_continuous(limits = c(0, 1), breaks = seq(0, 1, .1)) +
annotate('text', x = 0.99, y = 1, label = 'Happy / Upbeat') +
annotate('text', x = 0.99, y = 0, label = 'Mellow / Peaceful') +
annotate('text', x = 0.01, y = 0, label = 'Sad / Slow') +
annotate('text', x = 0.05, y = 1, label = 'Aggressive / Fast Paced') +
labs(x = "Positivity",
y = "Energy",
color = 'Album',
title = paste(df$artist_name, ' Song Distribution', sep = ""),
caption = paste('Data collected via spotifyr Package on ', mdyDate, sep = "")) +
theme_jacob() +
theme(legend.position = 'top')
ggplotly(p, tooltip = c('text')) %>%
layout(title = list(text = paste0(paste(df$artist_name, ' Song Distribution', sep = ""))))
下面是 plot 外觀的示例,它變形但在我的 shiny 儀表板中是正確的尺寸。 你可以看到它在任何地方都在使用我的主題,除了實際的 plot 它變成默認的白色背景並且知道如何解決這個問題。 如果有人有任何建議,我將不勝感激!
您需要在theme_jacob()
中聲明panel.background = element_rect(fill = "floralwhite")
) 。 那應該行得通。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.