[基本上,我希望标记为8的点读为“不喜欢”,标记为18的点读为“喜欢”。我想删除图例中的其他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())
您可以在breaks
中添加labels
和scale_size_continuous
:
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())
它回答了您的问题吗?