2017-09-11 18 views
0

내가 윤곽 플롯 만들기 위해 노력하고 그 다음과 같이 보입니다 (또는 레벨 플롯을, 나는 특히 어느 하나를 걱정하지 않는다) :격자에서 등고선에 색상을 어떻게 추가합니까?

contourplot(z~x*y, data=df1, xlim=c(0,100), ylim=c(0,50), 
      scales=list(x=list(at=c(0,20,40,60,80,100)), 
         y=list(at=c(0,10,20,30,40,50))), 
      at=seq(0,5000,by=500)) 
:

enter image description here

이 코드를

contourplot(z~x*y, data=df1, xlim=c(0,100), ylim=c(0,50), 
      scales=list(x=list(at=c(0,20,40,60,80,100)), 
         y=list(at=c(0,10,20,30,40,50))), 
      at=seq(0,5000,by=500), region=T, 
      colorkey=list(at=seq(0,5000,by=10)), col.regions=rainbow(5000)) 

나는이 끔찍한 결과를 얻을 : 잘 작동하지만 나는이 같은 색상을 추가하려고하고 때

enter image description here

나는 문제가 주로 규모하지만 at 또는 col.regions을 위해 내가 결과를 변경할 수 없습니다 시도 값에 상관없이의 생각합니다. 나는 심지어 interpolate 옵션을 시도했지만 do not snot이 차이를 만듭니다. 나는 많은 것을 수색했지만 격자의 문서가 조금 복잡하다는 것을 알아야한다.

structure(list(x = c(99.9735523336143, 99.9735523336143, 99.9735523336143, 
9.99735523336143, 99.9735523336143, 99.9735523336143, 99.9735523336143, 
99.9735523336143, 9.99735523336143, 99.9735523336143, 9.99735523336143, 
9.99735523336143, 9.99735523336143, 9.99735523336143, 9.99735523336143, 
9.99735523336143, 19.9947104667229, 19.9947104667229, 19.9947104667229, 
19.9947104667229, 19.9947104667229, 19.9947104667229, 19.9947104667229, 
19.9947104667229, 29.9920657000843, 29.9920657000843, 29.9920657000843, 
29.9920657000843, 29.9920657000843, 29.9920657000843, 29.9920657000843, 
29.9920657000843, 39.9103904572927, 39.9103904572927, 39.9103904572927, 
39.9103904572927, 39.9103904572927, 39.9103904572927, 39.9103904572927, 
39.9103904572927, 49.9867761668072, 49.9867761668072, 49.9867761668072, 
4.99867761668072, 49.9867761668072, 49.9867761668072, 49.9867761668072, 
49.9867761668072, 4.99867761668072, 49.9867761668072, 4.99867761668072, 
4.99867761668072, 4.99867761668072, 4.99867761668072, 4.99867761668072, 
4.99867761668072, 60.0631618763217, 60.0631618763217, 60.0631618763217, 
60.0631618763217, 60.0631618763217, 60.0631618763217, 60.0631618763217, 
60.0631618763217, 69.9419713954535, 69.9419713954535, 69.9419713954535, 
69.9419713954535, 69.9419713954535, 69.9419713954535, 69.9419713954535, 
69.9419713954535, 79.8207809145854, 79.8207809145854, 79.8207809145854, 
79.8207809145854, 79.8207809145854, 79.8207809145854, 79.8207809145854, 
79.8207809145854, 90.0947428144825, 90.0947428144825, 90.0947428144825, 
90.0947428144825, 90.0947428144825, 90.0947428144825, 90.0947428144825, 
90.0947428144825), y = c(0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.0999735523336143, 0.999735523336143, 19.9947104667229, 
1.99947104667229, 49.9867761668072, 0.499867761668072, 4.99867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.0999735523336143, 0.999735523336143, 19.9947104667229, 
1.99947104667229, 49.9867761668072, 0.499867761668072, 4.99867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072, 0.0999735523336143, 0.499867761668072, 
9.99735523336143, 0.999735523336143, 19.9947104667229, 1.99947104667229, 
49.9867761668072, 4.99867761668072), z = c(7.70262939725884, 
72.4762038498177, 1897.66010932237, 1.58054830233696, 165.070646557113, 
3792.42153530273, 356.278306229365, 9223.47853672023, 14.2758673767137, 
935.839000278543, 341.884101039707, 31.701193606272, 665.004073393329, 
66.9391931173054, 1509.15007815714, 171.754281181158, 2.89064204660586, 
26.2635839730677, 636.27993673818, 58.5156364281774, 1243.02434222159, 
123.885961157754, 2852.46703855471, 318.792649405134, 3.97493187787477, 
36.3111148789109, 889.55438527022, 81.1632049285379, 1744.63858516148, 
172.284250494152, 4044.24262993302, 444.58461882461, 4.86420556288387, 
44.6549593184585, 1105.67331471408, 100.121759918144, 2176.12813241023, 
213.072583938431, 5090.54862806588, 551.33727936112, 5.608738003459, 
51.7306506719939, 1294.26413375778, 0.827199861040891, 116.33438144459, 
2555.52749317869, 248.208540590425, 6028.1869116069, 7.44790194067698, 
643.985400190343, 177.310068151686, 16.5109365887457, 344.080667093976, 
34.8178598080871, 776.206332364582, 89.2039775124962, 6.21939893932657, 
57.6140181031486, 1455.92520463951, 129.934909189257, 2883.12188866332, 
277.918147781392, 6852.31788369484, 722.963381835502, 6.70936909598539, 
62.4057616449996, 1591.87930397262, 141.11465788703, 3160.532277617, 
302.546915494946, 7561.72493964819, 789.007565625702, 7.10911809960051, 
66.3821496606545, 1708.59117356901, 150.482643243694, 3400.26770836962, 
323.370848584576, 8184.13138429934, 845.374097718433, 7.44465742618642, 
69.7893126020086, 1812.39459545251, 158.596014882138, 3614.91792337778, 
341.585243605719, 8749.51748025968, 895.192251986793)), .Names = c("x", 
"y", "z"), row.names = c(NA, -88L), class = "data.frame") 
+1

는 [여기] 좋은 제안이있다 (https://stackoverflow.com/questions/7851602/methods-for-doing-heatmaps- : 당신은 일부 데이터 논쟁을 수행해야합니다 레벨 윤곽 플롯 및 육각형 비닝) –

답변

2

latticeExtra 패키지에서 panel.2dsmoother를 추가하는 것은 당신에게 (상대적으로) 부드럽게 찾고 색상을 줄 것이다 :

data.frame

이있다. 당신이 자세히 보면하지만, 가장자리는 여전히 약간 들쭉날쭉 다음과 같습니다 grpahics 패키지에서 당신이 격자 패키지 옵션으로 제한되지 않은 경우

contourplot(z~x*y, data=df1, xlim=c(0,100), ylim=c(0,50), 
      scales=list(x=list(at=c(0,20,40,60,80,100)), 
         y=list(at=c(0,10,20,30,40,50))), 
      at=seq(0,5000,by=500), region=T, 
      colorkey=list(at=seq(0,5000,by=10)), 
      col.regions=rainbow(5000), 
      panel = latticeExtra::panel.2dsmoother) 

contourplot

, filled.contour 오히려 좋은 보인다.

df2 <- tidyr::spread(df1, y, z) 
df.x <- df2$x 
df.y <- as.numeric(colnames(df2)[-1]) 
df.z <- as.matrix(df2[,-1]) 

filled.contour(df.x, df.y, df.z, 
       nlevels = 10, 
       col = rainbow(10), 
       plot.axes = { 
       axis(1) 
       axis(2) 
       contour(df.x, df.y, df.z, add = T)} 
       ) 

filled.contour

+0

고맙습니다! 또한이 링크는 정말 유용하며 많은 유용한 정보를 담고 있습니다. – rs028