In einer previous question habe ich ein Konturplot reproduziert, das mit dem Feld packages in ggplot2 generiert wurde (vollständiges Beispiel unten). Das einzige Problem ist, ich möchte die Platzierung der Kontur-Etiketten in contour()
replizieren, die standardmäßig auf der "flachsten" Teil der Linie sind - das zweite Bild könnte warum zeigen. Ich bin ratlos, wie ich diese Berechnung einstelle. Ich sehe here, dass es möglich ist, die Daten zu nehmen, die verwendet werden, um die Höhenlinien zu generieren, und dann geom_text()
könnte verwendet werden, um den Text zu plotten. Was bleibt, ist herauszufinden, wie man den "flachsten" Teil berechnet. Ideen?Zeichnen von Beschriftungen auf flachen Abschnitten von Konturlinien in ggplot2
library(fields)
library(ggplot2)
library(reshape)
library(directlabels)
sumframe<-structure(list(Morph = c("LW", "LW", "LW", "LW", "LW", "LW", "LW", "LW", "LW", "LW", "LW", "LW", "LW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW", "SW"), xvalue = c(4, 8, 9, 9.75, 13, 14, 16.25, 17.25, 18, 23, 27, 28, 28.75, 4, 8, 9, 9.75, 13, 14, 16.25, 17.25, 18, 23, 27, 28, 28.75), yvalue = c(17, 34, 12, 21.75, 29, 7, 36.25, 14.25, 24, 19, 36, 14, 23.75, 17, 34, 12, 21.75, 29, 7, 36.25, 14.25, 24, 19, 36, 14, 23.75), zvalue = c(126.852666666667, 182.843333333333, 147.883333333333, 214.686666666667, 234.511333333333, 198.345333333333, 280.9275, 246.425, 245.165, 247.611764705882, 266.068, 276.744, 283.325, 167.889, 229.044, 218.447777777778, 207.393, 278.278, 203.167, 250.495, 329.54, 282.463, 299.825, 286.942, 372.103, 307.068)), .Names = c("Morph", "xvalue", "yvalue", "zvalue"), row.names = c(NA, -26L), class = "data.frame")
sumframeLW<-subset(sumframe, Morph=="LW")
# FIELDS CONTOUR PLOT:
surf.teLW<-Tps(cbind(sumframeLW$xvalue, sumframeLW$yvalue), sumframeLW$zvalue, lambda=0.01)
summary(surf.teLW)
surf.te.outLW<-predict.surface(surf.teLW)
image(surf.te.outLW, col=tim.colors(128), xlim=c(0,38), ylim=c(0,38), zlim=c(100,400), lwd=5, las=1, font.lab=2, cex.lab=1.3, mgp=c(2.7,0.5,0), font.axis=1, lab=c(5,5,6), xlab=expression("X value"), ylab=expression("Y value"),main="LW plot")
contour(surf.te.outLW, lwd=2, labcex=1, add=T)
# GGPLOT2 CONTOUR PLOT:
LWsurfm<-melt(surf.te.outLW)
LWsurfm<-rename(LWsurfm, c("value"="z", "X1"="x", "X2"="y"))
LWsurfms<-na.omit(LWsurfm)
LWp<-ggplot(LWsurfms, aes(x,y,z=z))+geom_tile(aes(fill=z))+stat_contour(aes(x,y,z=z, colour=..level..), colour="black", size=0.6)+scale_fill_gradientn(colours=tim.colors(128))
LWp
LWp<-direct.label(LWp)
Mit dem 'LWSWsurf' Datenrahmen und dem Kommentar von Baptiste, das ist näher an dem, wonach ich suche, obwohl es immer noch nicht so schön aussieht wie ich ' d wie: 'levelplot (z ~ x * y | Morph, Daten = LWSWsurf, Kontur = TRUE, label.style =" align ", pretty = WAHR, col.regions = tim.colors (128), labels = TRUE)' – rebeccmeister