簡體   English   中英

Plot 多條曲線在同一個 plot 在 R

[英]Plot multiple curves in the same plot in R

我想在同一 plot 中的 plot 3 曲線:

curve(dweibull(x, shape=0.5, scale = 1), from=0, to=5)
par(new=TRUE)
curve(dweibull(x, shape=1, scale = 1), from=0, to=5)
par(new=TRUE)
curve(dweibull(x, shape=1.5, scale = 1), from=0, to=5)

我知道使用par(new=TRUE)將 plot 曲線在同一 plot 但我有三個 y 軸塗抹在一起,如下所示: 在此處輸入圖像描述

如何獲得一個清晰的 y 軸?

使用geom_functionggplot選項,如下所示:

library(ggplot2)
ggplot() + 
  geom_function(fun = function(x) sin(x)) +
  geom_function(fun = function(x) cos(x)) +
  geom_function(fun = function(x) 3*x) +
  labs(x = "x", y = "y") +
  theme_bw()

使用reprex v2.0.2創建於 2022-08-27

使用add=TRUE如下所示:

curve(dweibull(x, shape=0.5, scale = 1), from=0, to=5)
par(new=TRUE)
curve(dweibull(x, shape=1, scale = 1), from=0, to=5,  add=TRUE)
par(new=TRUE)
curve(dweibull(x, shape=1.5, scale = 1), from=0, to=5, add=TRUE)

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM