Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have used the following code to plot a beta curve:

p <- seq(0, 1, length=100)
plot(p, dbeta(p, 5, 7), ylab="density", type="l", col=4)

I wanted to plot two curves on the same graph and so repeated the second line using different numerical values in place of the 5 and 7. This resulted in the second curve being printed on a different graph (i.e. I got two separate graphs). Could anyone explain how to get both curves on the same graph?

question from:https://stackoverflow.com/questions/65933746/plotting-beta-curves-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
254 views
Welcome To Ask or Share your Answers For Others

1 Answer

A solution with ggplot:

library(ggplot2)

p= as.data.frame(seq(0,6,length=100))

ggplot(p) +
  stat_function(fun = function(p) dbeta(p, 5, 7), color = "red", size = 1) +
  xlab("beta curve")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...