如何调整和删除交叉表图中的图例标签?

How do I adjust and remove the legend labels in my crosstab plot?

基本上,我希望标有 8 的点读作 "Disliked",标有 18 的点读作 "Liked." 我想删除图例中的其他 4 个点。我不确定那些人是如何到达那里的。

我试过使用 scale_fill_discrete() 和 scale_fill_manual(),但它们在这里不起作用。有什么建议吗?

  #Load libraries
  library(ggplot2)
  library(dplyr)

  #Specify foods and countries
  foods <- c("cake", "cookies", "chocolate", "brownies")
  nations <- c("[![Belarus][1]][1]", "Zimbabwe", "Tanzania", "Morocco")

  #Create the data frame
  crosstab <- expand.grid(foods, nations)
  crosstab$value <- c(8, 8, 18, 18, 18, 18, 8, 18, 18, 18, 8, 18, 18, 8, 8, 18)

  #Plot the visualization
  final_plot <- ggplot(crosstab, aes(Var1, Var2)) + geom_point(aes(size = value), color = "#3484DA") + xlab("") + ylab("")

  #Add design elements
  final_plot + scale_size_continuous(range = c(5, 10)) +
    scale_x_discrete(position = "top") +
    theme(legend.position = "bottom",
          legend.title = element_blank(),
          legend.spacing.x = unit(0.1, "inches"),
          axis.text.x = element_text(size = 10.5, face = "bold"),
          axis.text.y = element_text(size = 10.5, face = "bold"),
          axis.ticks = element_blank(),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          panel.background = element_blank())

您可以在 scale_size_continuous 中添加 breakslabels:

  final_plot + scale_size_continuous(range = c(5, 10), breaks = c(8,18), labels = c("Disliked","Liked")) +
    scale_x_discrete(position = "top") +
    theme(legend.position = "bottom",
          legend.title = element_blank(),
          legend.spacing.x = unit(0.1, "inches"),
          axis.text.x = element_text(size = 10.5, face = "bold"),
          axis.text.y = element_text(size = 10.5, face = "bold"),
          axis.ticks = element_blank(),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          panel.background = element_blank())

它能回答您的问题吗?