[英]R - multiple graphs in one plot, but transparency for overlying parts of graph not working
我正在R中創建一些海拔數據的頻率/密度圖。下面的代碼非常適合在一張圖中獲取兩個不同的變量,每個密度和頻率。 因此,總共有兩個條形圖和兩條線。
問題是,條形圖彼此重疊,我無法正確設置“ alpha”的透明度設置。 這是我需要幫助的地方。 我想這是一個非常簡單的問題。
我已經在代碼中的不同位置嘗試了alpha
函數,但是沒有用。
hist(Lake_DF1[[6]], col=c("#006CFF"), border = "black", prob = TRUE,
# show densities instead of frequencies
breaks = 60, xlim = c(14,17), xlab = "Height [m]", main = "DTLB 6")
lines(density(na.omit(Lake_DF1[[6]])), lwd = 2)
hist(Buffer_DF1[[6]], col = c("#FF9900", alpha=0.4), border = "black", prob = TRUE,
# show densities instead of frequencies
breaks = 60, xlim = c(14,17), add=TRUE)
lines(density(na.omit(Buffer_DF1[[6]])), lwd = 2)
考慮使用允許r參數的?rgb
。 另外,為了更好地進行顏色比較,請使用不同alpha值的相同顏色。
藍色
# CONVERSION: #006CFF --> rgb(0,108,255)
hist(Lake_DF1[[6]], col = rgb(0/255, 108/255, 255/255, 0.4), border = "black", prob = TRUE,
# show densities instead of frequencies
breaks = 60, xlim = c(14,17), xlab = "Height [m]", main = "DTLB 6")
lines(density(na.omit(Lake_DF1[[6]])), lwd = 2)
hist(Buffer_DF1[[6]], col = rgb(0/255, 108/255, 255/255, 0.3),
border = "black", prob = TRUE,
# show densities instead of frequencies
breaks = 60, xlim = c(14,17), add=TRUE)
橙子
# CONVERSION: #FF9900 --> rgb(255,153,0)
hist(Lake_DF1[[6]], col = rgb(255/255, 153/255, 0/255, 0.4), border = "black", prob = TRUE,
# show densities instead of frequencies
breaks = 60, xlim = c(14,17), xlab = "Height [m]", main = "DTLB 6")
lines(density(na.omit(Lake_DF1[[6]])), lwd = 2)
hist(Buffer_DF1[[6]], col = rgb(255/255, 153/255, 0/255, 0.3),
border = "black", prob = TRUE,
# show densities instead of frequencies
breaks = 60, xlim = c(14,17), add=TRUE)
lines(density(na.omit(Buffer_DF1[[6]])), lwd = 2)
數據
set.seed(8302019)
data_tools <- c("sas", "stata", "spss", "python", "r", "julia")
#################
### DATA BUILD
#################
Lake_DF1 <- data.frame(
group = sample(data_tools, 500, replace=TRUE),
int = sample(1:15, 500, replace=TRUE),
num1 = rnorm(500),
num2 = runif(500),
num3 = rnorm(500),
num4 = runif(500),
num5 = rnorm(500),
num6 = runif(500)
)
Buffer_DF1 <- data.frame(
group = sample(data_tools, 500, replace=TRUE),
int = sample(1:15, 500, replace=TRUE),
num1 = runif(500, 14, 17),
num2 = runif(500, 14, 17),
num3 = runif(500, 14, 17),
num4 = runif(500, 14, 17),
num5 = runif(500, 14, 17),
num6 = runif(500, 14, 17)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.