จะแก้ไขจำนวนขีดและใช้การไล่ระดับสีแบบหลายสีใน ggtern ได้อย่างไร

ฉันกำลังทดลองใช้โค้ดนี้ และสิ่งที่ฉันพบว่าน่าสนใจคือจำนวนเห็บเปลี่ยนไป เมื่อฉันวางแผน ในกรณีของฉันฉันได้รับสิ่งนี้:

ป้อนคำอธิบายรูปภาพที่นี่

รหัสที่ใช้เหมือนกับใน OP:

#Orignal Data as per Question
a <- c(0.1, 0.5,0.5, 0.6, 0.2, 0          , 0         , 0.004166667, 0.45) 
b <- c(0.75,0.5,0  , 0.1, 0.2, 0.951612903,0.918103448, 0.7875     , 0.45)
c <- c(0.15,0  ,0.5, 0.3, 0.6, 0.048387097,0.081896552, 0.208333333, 0.10) 
d <- c(500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04) 
df <- data.frame(a, b, c, d)

#For labelling each point.
df$id <- 1:nrow(df)

#Build Plot
ggtern(data=df,aes(x=c,y=a,z=b),aes(x,y,z)) + 
  stat_density2d(geom="polygon",
                 n=400,
                 aes(fill=..level..,
                 weight=d,
                 alpha=abs(..level..)),
                 binwidth=100) + 
  geom_density2d(aes(weight=d,color=..level..),
                 n=400,
                 binwidth=100) +
  geom_point(aes(fill=d),color="black",size=5,shape=21) + 
  geom_text(aes(label=id),size=3) + 
  scale_fill_gradient(low="yellow",high="red") + 
  scale_color_gradient(low="yellow",high="red") + 
  theme_tern_rgbw() + 
  theme(legend.justification=c(0,1), legend.position=c(0,1)) + 
  guides(fill = guide_colorbar(order=1),
         alpha= guide_legend(order=2),
         color="none") + 
  labs(  title= "Ternary Plot and Filled Contour",
         fill = "Value, V",alpha="|V - 0|")

#Save Plot
ggsave("TernFilled.png")

ฉันพยายามเพิ่มจำนวนเห็บเป็น 11 แต่ก็ไม่มีโชค สามารถระบุจำนวนขีดได้อย่างไร

การไล่ระดับสีหลายสี

และเป็นไปได้ไหมที่จะไล่ระดับสีหลายสีแทนการไล่ระดับสีสองสี ฉันได้ลองตั้งค่าแล้ว

scale_fill_gradient(low="yellow",high="red")

to

scale_fill_gradient(low="blue", mid = "yellow",  high="red")

แต่ไม่มีการเปลี่ยนแปลง สามารถทำได้อย่างไร?


person Tom Kurushingal    schedule 21.05.2015    source แหล่งที่มา
comment
@Nicholas Hamilton แนะนำให้คุณใช้ scale_fill_gradient2 โปรดทราบ 2   -  person Henrik    schedule 21.05.2015


คำตอบ (1)


ggtern 2.0.1 ซึ่งเผยแพร่บน CRAN เมื่อสองสามวันก่อนหลังจากเขียนแพ็คเกจใหม่ทั้งหมดเพื่อให้เข้ากันได้กับ ggplot2 2.0.0 คุณสามารถดูสรุปฟังก์ชันใหม่ใน ggtern 2.0.X ได้ที่นี่:

ดังนั้นในส่วนที่เกี่ยวกับจำนวนเห็บ เว้นแต่จะมีการระบุไว้อย่างชัดเจนผ่านอาร์กิวเมนต์ 'breaks' ในแต่ละ scale_X_continuous(...) [โดยที่ X = T, L หรือ R] หรือผ่าน limit_tern(...) โดยที่อาร์กิวเมนต์ 'breaks' เดียวกันถูกส่งผ่านไปยังทั้งสาม สเกลต่อเนื่อง ggtern จะพยายามคาดเดาให้ดีที่สุด

พิจารณาชุดตัวอย่างต่อไปนี้:

#Set up a plot
df   = data.frame(x=1,y=1,z=1)
base = ggtern(data=df,aes(x,y,z)) + geom_point()

#1. The default case, best guess.
base 

#2. A reduced scale limit, with best guess.
base + limit_tern(.5,.5,.5)

#3. Manual breaks passed to all three ternary scales
base + limit_tern(breaks = seq(0,1,by=0.05))

#4. Manual breaks passed to all three ternary scales, under limited region
base + limit_tern(.5,.5,.5,breaks = seq(0,1,by=0.05))

#5. Manual breaks passed to a single ternary scale, the other two are done by best guess
base + scale_T_continuous(breaks  = seq(0,1,by=0.05))
person Nicholas Hamilton    schedule 18.01.2016