2016-10-24 21 views
0

我繪製在R.數據我運行以下兩個命令:如何獲得[R劇情上繪製heat.color規模可變

plot(x = df$Latitude, df$Longitude, col = heat.colors(nrow(df)), type = "p") 

plot(x = df$Latitude, df$Longitude, col = df$feature, type = "p") 

第一線圖沿着漸變色點(具有較高值的​​點是紅色,具有較低值的點是黃色),第二行用由features給出的int值指示的顏色繪製數據。

但是,我想將兩者結合起來,以便使用feature的數值在刻度上用顏色繪製點。從某種意義上說,我想傳遞兩個參數到col。我怎樣才能做到這一點?

+0

看看'ggplot2'包 – timat

回答

1

你可以試試:

# some data 
set.seed(123) 
x <- rnorm(100) 

# Create some breaks and use colorRampPalette to transform the breaks into a color code 
gr <- .bincode(x, seq(min(x), max(x), len=length(x)), include.lowest = T) 
col <- colorRampPalette(c("red", "white", "blue"))(length(x))[gr] 

# the plot: 
plot(x, pch=16, col=col) 

enter image description here

了一段傳奇看到的解決方案herehere