Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 多密度绘图图例_R_Plot_Data Visualization_Probability Density - Fatal编程技术网

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)