我正在尝试在R中生成对数正态概率密度的图,其中有3种不同的对数和标准偏差日志。我尝试过以下方法,但我的图表太丑了,看起来并不好看。
x<- seq(0,10,length = 100)
a <- dlnorm(x, meanlog = 0, sdlog = 1, log = FALSE)
b <- dlnorm(x, meanlog = 0, sdlog = 1.5, log = FALSE)
g <- dlnorm(x, meanlog = 1.5, sdlog = 0.2, log = FALSE)
plot(x,a, lty=5, col="blue", lwd=3)
lines(x,b, lty=2, col = "red")
lines(x,g, lty=4, col = "green")
我甚至试图在右上方为每个平均日志和标准差日志添加图例,但它不适用于我。我想知道是否有人可以指导我。
答案 0 :(得分:1)
您的代码确实没有错。你忘了:
.navbar-toggle .icon-bar{background-color:white;}
.navbar-left {
overflow: auto;
font-weight: 200;
color: #fff;
background-color: #3d486f;
position: fixed;
top: 0px;
width: 250px;
height: 100%;
}
.navbar-left a { color: #fff; }
.navbar-left-header { margin: 15px 0; }
.navbar-left ul, .navbar-left li { list-style: none; }
.navbar-clear { clear: left; }
@media (max-width: 767px) {
.navbar-left {
position: relative;
width: 100%;
margin-bottom: 10px;
}
.navbar-left .navbar-toggle { display: block; }
}
@media (min-width: 768px) {
#menu-content { display: block; }
.navbar-left .navbar-toggle { display: none; }
}
; <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="navbar-left">
<div class="navbar-left-header">
Title
<button type="button" data-toggle="collapse" data-target="#menu-content" aria-expanded="false" aria-controls="navbar" class="collapsed navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-clear"></div>
<ul id="menu-content" class="collapse">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
</ul>
</div>
</div>
type = "l"
以保留所有行。以下是plot
的简单解决方案:
ylim
要添加图例,请使用
matplot
您还可以阅读matplot(x, cbind(a,b,g), type = "l", ylab = "density", main = "log-normal",
col = 1:3, lty = 1:3)
添加表达式。尝试将上面的legend("topright",
legend = c("mu = 0, sd = 1", "mu = 0, sd = 1.5", "mu = 1.5, sd = 0.2"),
col = 1:3,
lty = 1:3)
参数更改为:
?plotmath