【问题标题】:ggplotly theme inconsistency with ggplot2ggplotly 主题与 ggplot2 不一致
【发布时间】:2020-06-14 00:24:11
【问题描述】:

您好,我正在使用 ggplotly 来添加与我使用 ggplot2 制作的绘图的交互性,以获得闪亮的仪表板。情节正常运行,只是看起来很傻,因为它没有始终如一地使用我通常使用的主题( theme_jacob() )。我知道在将 plotly 函数应用于 ggplot 图时会出现很多问题,但我无法在线找到任何资源来解决我的特定问题。我在下面粘贴了我的代码。

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 = ""))))

下面是情节的示例,它被扭曲了,但在我闪亮的仪表板中是正确的尺寸。你可以看到它在任何地方都使用我的主题,除了它变成默认白色背景的实际情节以及如何解决这个问题。如果有人有任何建议,我将不胜感激!

【问题讨论】:

    标签: r ggplot2 themes ggplotly


    【解决方案1】:

    您需要theme_jacob() 中的声明panel.background = element_rect(fill = "floralwhite")。应该可以的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多