dum__dum 2023-02-12 20:09 采纳率: 100%
浏览 36
已结题

ggplot2如何添加y曲线

用ggplot2跑图,提示要添加y,不然会被后面的替代:
Scale for y is already present.
Adding another scale for y, which will replace the existing scale.

p2 <-plot(res_psa, type = "ac", max_wtp = 100000, log_scale = FALSE) +
  xlab("Willingness-to-pay threshold, × $1000/QALY")+
  scale_y_continuous(name="Probability that the intervention is cost-effective",
                     limits=c(0, 1),
                     breaks=seq(0,1,0.1))+                 
  #scale_color_manual(values = mycolors[1:2])+
  scale_size_manual(values = c(3,3))+
  theme_light()+
  ggtitle("Cost-effectiveness Acceptability Curves")+
  theme(
    axis.text.x=element_text(),
    strip.placement = "outside",
    strip.background = element_rect(),
    ##图形标题设置 字体和大小
    plot.title = element_text(family='Times', face='bold.italic',size = 22),
    ##x坐标轴
    axis.title.x = element_text(family = 'Times',face = 'bold',size =15),
    ##y坐标轴
    axis.title.y = element_text(family = 'Times',face = 'bold',size=10),
    #图例标题
    legend.title = element_text(family = 'Times',face = 'bold',size=10),
    #图例内的字体
    legend.text = element_text(family = 'Times',face = 'bold',size=12),
    #图例位置
    legend.position="bottom"
  )

请问如何添加?

  • 写回答

2条回答 默认 最新

  • 社区专家-Monster-XH 2023-02-12 21:12
    关注

    aes函数

    
    p2 <- ggplot(data = res_psa, aes(x = threshold, y = prob)) +
      geom_line(aes(color = prob > 0.5)) +
      xlab("Willingness-to-pay threshold, × $1000/QALY") +
      ylab("Probability that the intervention is cost-effective") +
      scale_y_continuous(limits=c(0, 1), breaks=seq(0, 1, 0.1)) +
      theme_light() +
      ggtitle("Cost-effectiveness Acceptability Curves") +
      theme(
        axis.text.x = element_text(),
        strip.placement = "outside",
        strip.background = element_rect(),
        plot.title = element_text(family='Times', face='bold.italic',size = 22),
        axis.title.x = element_text(family = 'Times',face = 'bold',size =15),
        axis.title.y = element_text(family = 'Times',face = 'bold',size=10),
        legend.title = element_text(family = 'Times',face = 'bold',size=10),
        legend.text = element_text(family = 'Times',face = 'bold',size=12),
        legend.position="bottom"
      )
    
    

    res_psa数据作为图形的数据源,用aes函数定义X轴(threshold)和Y轴(prob)。然后,你可以添加线型图(geom_line)来显示数据。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月22日
  • 已采纳回答 2月14日
  • 创建了问题 2月12日

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度