ggplot2不要图例_为什么ggplot2图例不显示在图中

在尝试使用ggplot2进行散点图绘制时,遇到图例未出现在图中的问题。通过调整代码,将颜色参数放入美学映射中,并使用`scale_color_manual`手动设置颜色,成功在图例的左上角显示了'Dataset 1'和'Dataset 2'。解决方案包括在`aes`中为每个数据集指定颜色,然后设置图例位置和颜色值。
摘要由CSDN通过智能技术生成

I use ggplot to scatterplot 2 datasets and want to show the legend in the top left. I tried some code but didn't work. I am not sure why this happened.

ggplot(mf, aes(log10(mf[,2]),mf[,1]))

+ ggtitle("Plot")

+ geom_point(color = "blue") + theme(plot.margin = unit(c(1,2,1,1), "cm"))

+ xlab("xxx") + ylab("yyy")

+ theme(plot.title = element_text(size=18,hjust = 0.5, vjust=4))

+ geom_point(data=mf2,aes(log10(mf2[,2]),mf2[,1]),color="red")

+ theme(axis.title.x = element_text(size = rel(1.3)))

+ theme(axis.title.y = element_text(size = rel(1.3)))

+ scale_color_discrete(name = "Dataset",labels = c("Dataset 1", "Dataset 2"))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值