[英]R add plot title
我有一個可以工作的圖表繪制功能:
fPlot <- function(ds, plot1) {
A <- ds$A [c(TRUE, FALSE)]
B <- ds$B [c(FALSE, TRUE)]
Concentration <- ds$Concentration
Time <- ds$Time
d <- data.frame(A = as.numeric(sub(',', '.', A)), B= as.numeric(sub(',', '.', B)), Time = as.numeric(sub(',', '.', Time)), Concentration = as.numeric(sub(',', '.', Concentration)))
d$Concentration <- factor(d$Concentration)
p <- ggplot (d, aes (A, B)) +
geom_point(aes(color = Concentration, shape = Concentration)) +
xlab ("A") +
ylab ("B") +
geom_abline(slope = 1, linetype = 2, color = "black") +
facet_wrap(vars(Concentration)) +
theme_bw()
pdf(plot1)
plot(p)
dev.off()
p
}
fPlot(ds, "plot1.pdf")
我想在函數中添加一個常見的標題(主)到圖表中,它將包含時間列中的值(在這種情況下,時間列的所有值都是 30 分鍾),所以我希望圖表的標題是30 分鍾,但如果“時間”列中分析集中的數據為 60 分鍾,那么我希望該函數 fPlot 將圖表的標題更改為 60 分鍾。
預先感謝您的幫助
示例數據集:
structure(list(A = c(2.78, NA, 3.78, NA, 6.67, NA, 12.4, NA,
3.56, NA), B = c(NA, 2.98, NA, 1.98, NA, 4.56, NA, 1.21, NA,
5.88), Concentration = c(10, 10, 10, 0.1, 0.1, 0.1, 1, 1, 1,
10), Time = c("30 min", "30 min", "30 min", "30 min", "30 min",
"30 min", "30 min", "30 min", "30 min", "30 min")), class = "data.frame", row.names = c(NA,
-10L))
我認為您正在尋找labs(title="")
,您可以根據數據集中的定義提供像 Time 這樣的變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.