R 多密度绘图图例
我有以下代码:R 多密度绘图图例,r,plot,data-visualization,probability-density,R,Plot,Data Visualization,Probability Density,我有以下代码: x <- seq(-25,25, by = .01) plot(x, dunif(x,-10,10), type = 'l', ylab = 'probability', lwd = 2) lines(x, dnorm(x,0,10), col = 'blue', lwd = 2) lines(x, dstudent_t(x,4,0,10), col = 'red', lwd = 2) lines(x, dcauchy(x,0,10), col = 'green', lwd
x <- seq(-25,25, by = .01)
plot(x, dunif(x,-10,10), type = 'l', ylab = 'probability', lwd = 2)
lines(x, dnorm(x,0,10), col = 'blue', lwd = 2)
lines(x, dstudent_t(x,4,0,10), col = 'red', lwd = 2)
lines(x, dcauchy(x,0,10), col = 'green', lwd = 2)
legend(1, 95, legend=c("Uniform (-10,10)", "Normal (0,10)", "Student t (4,0,10)", "Cauchy (0, 10)"),
col=c("black", "red", "blue", "green"), lty=1:2, cex=0.8)
x试试看
您的y=95
图例调用中的y=95
值远远超出了y轴范围。@jay.sf根据您的建议,图例有效!但是它在图例中显示的线有时是虚线,有时不是,如何将它更改为图例中所有分布的简单线?(至于制服和普通的)
最后一个问题。看起来我不能像这样分配绘图,就像我通常对ggplot所做的那样,将其保存为PDF格式。这里有什么选择
plot1 <- plot(x, dunif(x,-10,10), type = 'l', ylab = 'probability', lwd = 2)
lines(x, dnorm(x,0,10), col = 'blue', lwd = 2)
lines(x, dstudent_t(x,4,0,10), col = 'red', lwd = 2)
lines(x, dcauchy(x,0,10), col = 'green', lwd = 2)
legend("topleft", legend=c("Uniform (-10,10)", "Normal (0,10)", "Student t (4,0,10)", "Cauchy (0, 10)"),
col=c("black", "red", "blue", "green"), lty=1, cex=0.8)
plot1尝试legend(-20.04,legend=…)
或legend(“左上角”,legend=…)
。尝试过,但不幸的是与其中一个密度略微重叠。。
x <- seq(-25,25, by = .01)
plot(x, dunif(x,-10,10), type = 'l', ylab = 'probability', lwd = 2)
lines(x, dnorm(x,0,10), col = 'blue', lwd = 2)
lines(x, dstudent_t(x,4,0,10), col = 'red', lwd = 2)
lines(x, dcauchy(x,0,10), col = 'green', lwd = 2)
legend("topleft", legend=c("Uniform (-10,10)", "Normal (0,10)", "Student t (4,0,10)", "Cauchy (0, 10)"),
col=c("black", "red", "blue", "green"), lty=1:2, cex=0.8)
lty=1
plot1 <- plot(x, dunif(x,-10,10), type = 'l', ylab = 'probability', lwd = 2)
lines(x, dnorm(x,0,10), col = 'blue', lwd = 2)
lines(x, dstudent_t(x,4,0,10), col = 'red', lwd = 2)
lines(x, dcauchy(x,0,10), col = 'green', lwd = 2)
legend("topleft", legend=c("Uniform (-10,10)", "Normal (0,10)", "Student t (4,0,10)", "Cauchy (0, 10)"),
col=c("black", "red", "blue", "green"), lty=1, cex=0.8)