ggplotly 中的 Aes

Aes in ggplotly

ggplotly 从 aes 打印一些东西,即 "alpha" 和 "Continent",我不知道为什么会这样.. 请帮助删除它!

看右上角->

使用ggplot的部分代码:

server <- function(input, output) {    
  observe({
    output$plot1 <- renderPlotly({
      p <- ggplot(df1(), aes(x = df1()[,4], y = Happiness.Score))
      p <- p + geom_point(size = 2, aes(text = paste("Country:", df1()[,1]), color = Continent,  alpha = 0.85)) + 
        labs(title = "How happy is the country?", x = names(df1())[4], y = "Happiness Score") + 
        theme_light(base_size = 12) + ylim(2,8) 
      ggplotly(p, tooltip = c("text", "y"))
    })
  })

Continent 是图例标题。要更改它,您可以这样做:

...... + scale_color_discrete(name = "MY_LEGEND_TITLE")

要删除 alpha,请将其设置在 aes 之外:

geom_point(aes(text = paste("Country:", df1()[,1]), color = Continent), 
           size = 2, alpha = 0.85)