gpt4 book ai didi

r - 如何使用带有 knitr 的 ggplot2 删除 _printed_ 输出警告

转载 作者:行者123 更新时间:2023-12-02 06:59:18 24 4
gpt4 key购买 nike

GGplot2 在绘图中使用 scale_colour_gradient 两次时会打印出警告,我无法在 knitr 中抑制。这是我的浏览器在编织 RHTML 文件后的屏幕截图:

enter image description here

我需要为渐变着色,一种用于线条( yield 曲线便宜/昂贵),另一种用于相似但略有不同的工具(彩色点)。

这是我的 ggplot 代码:

ggp <- ggplot(polys, aes(x = xvals, y = yvals)) + 
#geom_polygon(aes(fill = - value, group = id, alpha = value)) + # lovely blue
geom_polygon(aes(fill = value, group = id, alpha = value)) + # lovely shiny light blue middle draw me in
scale_x_log10(breaks = xaxtickpos, minor_breaks = NULL) +
theme(legend.position = "none", panel.background = element_rect(fill = "grey85", colour = NA)) +
xlab("maturity") + ylab("bps")
ggp <- ggp + geom_line(data = quanmelt[quanmelt[, "percentile"] %in% outerthresh, ],
aes(x = mat, y = value, group = percentile), colour = "white", size = 2)
ggp <- ggp + geom_line(data = quanmelt[quanmelt[, "percentile"] %in% innerthresh, ],
aes(x = mat, y = value, group = percentile), colour = "white", size = 1,
linetype = "dotted")
#add last few days line/today (this doesn't work very well hence commented out)
todayback <- todayline[todayline$daysback == 2, ] # get this historic lines
ggp <- ggp + geom_smooth(data = todayback, aes(x = mat, y = value, group = daysback),
colour = "darkred", linetype = "dashed",
se = FALSE, size = 1, method = "loess", span = (ifelse(smooth, 0.3, 0.1)))
#add boxplot
ggp <- ggp + geom_boxplot(data = meltcdlong, aes(x = mat, y = value, group = bond), outlier.size = NA,
colour = "grey30", alpha = 0.5, size = 0.2, width = 0.025)

# add the latest point
ggp <- ggp + geom_point(data = latestcdpoint, aes(x = mat, y = value, group = bond))
# now do labels (twice - one for above, one for below)
ggp <- ggp + geom_text(data = latestcdpoint[latestcdpoint$adjustvertvec == 1, ], aes(x = mat, y = labelposies, label = label),
angle = 90, colour = "grey20", size = 3, hjust = 0, alpha = 0.5)
ggp <- ggp + geom_text(data = latestcdpoint[latestcdpoint$adjustvertvec == 0, ], aes(x = mat, y = labelposies, label = label),
angle = 90, colour = "grey20", size = 3, hjust = 1, alpha = 0.5)
#now print a nice z-score graded colour line for the curve
todaytoday <- todayline[todayline$daysback == 0, ]
minz <- min(rescale(todaytoday[, "zscore"])) # for scaling of z-score line gradient colours
maxz <- max(rescale(todaytoday[, "zscore"]))
bpspline <- smooth.spline(todaytoday$mat, todaytoday$value, spar = 0.4) # Smooth out the curve with lots of points
zscorespline <- smooth.spline(todaytoday$mat, todaytoday$zscore) # and smooth out the zscores too
xplot <- seq(2, maxmat, by = 0.1)
todayplotter <- data.frame(mat = xplot, value = predict(bpspline, xplot)$y,
zscore = rescale(c(-5, 5, predict(zscorespline, xplot)$y))[-1:-2]) # build the plotter
ggp <- ggp + geom_path(data = todayplotter, aes(x = mat, y = value, colour = zscore), size = 2, linejoin = "bevel") +
scale_colour_gradientn(colours = gradientcolours, values = gradientscale, limits = c(minz, maxz))
#and the title
ggp <- ggp + ggtitle(cCode)
# now the test chart
mm <<- meltcdrecent[meltcdrecent$daysback == 0, ]
ggp <- ggp + geom_point(data = mm, aes(x = mat, y = value, colour = rescale(c(-5, 5, zscore))[-1:-2]), size = 6) +
scale_colour_gradientn(colours = gradientcolours, values = gradientscale, limits = c(0, 1))
ggp <- ggp + geom_point(data = mm, aes(x = mat, y = value), colour = "black", size = 4.5)
ggp <- ggp + geom_text(data = mm, aes(x = mat, y = value), label = round(mm$zscore, 1), colour = "white", size = 2, alpha = 0.7)

这很复杂,但你可以看到我有两个 scale_colour_gradient(s)。

这是我的 knitr 代码:

  <!--begin.rcode changer, echo=FALSE, fig.height=4.5, fig.width=8
for(x in ac) {
g <- ggCD(x, plotit = FALSE)
suppressWarnings(plot(g$cdChart))
}
end.rcode-->

我想要么摆脱这些警告(它们不是真正的真正警告,所以 suppressWarnings 不起作用),或者,以不会产生这种情况的方式使用 scale_colour_gradient首先是文本。

最佳答案

改变

<!--begin.rcode changer, echo=FALSE, fig.height=4.5, fig.width=8

进入

<!--begin.rcode changer, echo=FALSE, fig.height=4.5, fig.width=8, message=FALSE

关于r - 如何使用带有 knitr 的 ggplot2 删除 _printed_ 输出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24828341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com