2013-02-05 37 views
6

Lấy ví dụ dữ liệu sau:Làm cách nào để tạo biểu đồ biến đổi theo kiểu bản đồ nhiệt trong một bố cục mạng?

x <- rnorm(10000) 
y <- rnorm(10000) * x 
z <- rnorm(10000) * y 
df <- data.frame(x,y,z) 

Chúng ta có thể tạo ra một ma trận đồ phân tán như sau:

splom(df) 

enter image description here

Nhưng do số lượng lớn các điểm chồng chéo rất khó để đo mật độ.

Có cách nào đơn giản để thay thế từng ô bằng bản đồ nhiệt biểu đồ hai biến, như được tạo bởi squash không?

library(squash) 
hist2(df$x, df$y) 

enter image description here

Trả lời

8

Các panel.hexbinplot thuận tiện cho việc tập hợp dữ liệu lớn.

library(hexbin) 
splom(df, panel=panel.hexbinplot) 

enter image description here

Bạn có thể tùy chỉnh chức năng bảng điều khiển như thế này:

library(hexbin) 
splom(df, 
     panel = function(x, y, ...){ 
     panel.hexbinplot(x, y, style = "nested.lattice", 
         type = c("g", "smooth"),col='blue', ...) 
     }, 
     pscale=0, varname.cex=0.7) 

Bạn có thể chơi với teh style tham số.

enter image description here

+0

Điều này có vẻ rất hứa hẹn, nhưng tôi nhận được lỗi sau: Lỗi trong grid.Call.graphics (L_downviewport, tên $ name, strict): Chế độ xem 'plot_01.panel.1.1.off.vp' không được tìm thấy – saffsd

+0

@saffsd nó lạ. Hãy thử nó trong một phiên R mới xin vui lòng. – agstudy

+0

Lỗi vẫn tồn tại trong một phiên mới. Để tham khảo: R phiên bản 2.15.1 (2012-06-22) - "Marshmallows Roasted" Nền tảng: x86_64-pc-linux-gnu (64-bit) – saffsd

0

đây không phải là phương pháp mà bạn yêu cầu, nhưng sẽ giúp bạn giải quyết các vấn đề cơ bản bạn đã mô tả :)

# run the code you've provided 
library(lattice) 
x <- rnorm(10000) 
y <- rnorm(10000) * x 
z <- rnorm(10000) * y 
df <- data.frame(x,y,z) 

# figure out what ten percent of the total records are 
ten.percent <- nrow(df)/10 

# create a new data frame `df2` containing 
# a randomly-sampled ten percent of the original data frame 
df2 <- df[ sample(nrow(df) , ten.percent ) , ] 

# now `splom` that.. and notice it's easier to see densities 
splom(df2) 
4

đây là một lựa chọn đó là hơn trong- phù hợp với yêu cầu ban đầu của bạn

# run the code you've provided 
library(lattice) 
x <- rnorm(10000) 
y <- rnorm(10000) * x 
z <- rnorm(10000) * y 
df <- data.frame(x,y,z) 

# look at each of these options one-by-one.. go slowly! 

# here's your original 
splom(df) 


# here each point has been set to very transparent 
splom(df , col="#00000005") 

enter image description here

# here each point has been set to moderately transparent 
splom(df , col="#00000025") 

enter image description here

# here each point has been set to less transparent 
splom(df , col="#00000050") 

enter image description here

+2

Một ý tưởng hay là làm cho các điểm nhỏ hơn, ví dụ: 'splom (df, col =" # 00000040 ", pch = '.')'. –

Các vấn đề liên quan