通过ggplot2向土壤分类三角形添加纹理类
Add texture classes to soil classification triangle via ggplot2
我有一些实验数据,想绘制在土壤分类三角形上以识别质地。我正在使用此处找到的三角形:
http://www.ggtern.com/2014/01/15/usda-textural-soil-classification/
我想将粘土、沙子和淤泥显示为点。
这是我的数据:
structure(list(Clay = c(1.67, 1.29, 1.1, 1.57, 1.52, 1.72, 1.53,
1.47, 1.34, 0.84, 1.18, 1.03, 1.1, 1.08, 1.41, 1.17), Silt = c(59.21,
59.39, 54.4, 57.65, 58.42, 60.17, 64.98, 60.67, 57.84, 55.73,
56.7, 50.8, 53.68, 57.92, 59.97, 56.62), Sand = c(39.09, 39.33,
44.5, 40.79, 40.04, 38.08, 33.47, 37.89, 40.81, 43.44, 42.11,
48.17, 45.24, 41.01, 38.63, 42.21)), .Names = c("Clay", "Silt",
"Sand"), row.names = c(NA, -16L), class = "data.frame")
感谢您的建议。
AT.
很抱歉 CRAN 删除了我的包,我才刚刚发现并会在有时间的时候解决这个问题,在此期间源仍然可用 HERE。
无论如何,您的解决方案很容易实现,将颜色和填充的 'aesthetic' 定义从 'global' 定义移动到仅特定于 geom_polygon(。 ..),如下所示:
让我们从(略微)修改的美国农业部分类开始,取自您问题中的 link:
# Load the required libraries
library(ggtern)
library(plyr)
library(grid)
# Load the Data. (Available in ggtern 1.0.3.0 next version)
data(USDA)
# Put tile labels at the midpoint of each tile.
USDA.LAB = ddply(USDA, 'Label', function(df) {
apply(df[, 1:3], 2, mean)
})
# Tweak
USDA.LAB$Angle = 0
USDA.LAB$Angle[which(USDA.LAB$Label == 'Loamy Sand')] = -35
# Construct the plot.
# NOTE aes(color=Label,fill=Label) in 3rd line below
base = ggplot(data = USDA, aes(y=Clay, x=Sand, z=Silt)) +
coord_tern(L="x",T="y",R="z") +
geom_polygon(alpha = 0.75, size = 0.5, color = 'black',aes(color=Label,fill=Label)) +
geom_text(data = USDA.LAB,
aes(label = Label, angle = Angle),
color = 'black',
size = 3.5) +
theme_rgbw() +
theme_showsecondary() +
theme_showarrows() +
custom_percent("Percent") +
theme(legend.justification = c(0, 1),
legend.position = c(0, 1),
axis.tern.padding = unit(0.15, 'npc')) +
labs(title = 'USDA Textural Classification Chart',
fill = 'Textural Class',
color = 'Textural Class')
base
现在您可以添加数据了:
df = structure(list(Clay = c(1.67, 1.29, 1.1, 1.57, 1.52, 1.72, 1.53, 1.47, 1.34, 0.84, 1.18, 1.03, 1.1, 1.08, 1.41, 1.17),
Silt = c(59.21,59.39, 54.4, 57.65, 58.42, 60.17, 64.98, 60.67, 57.84, 55.73,56.7, 50.8, 53.68, 57.92, 59.97, 56.62),
Sand = c(39.09, 39.33, 4.5, 40.79, 40.04, 38.08, 33.47, 37.89, 40.81, 43.44, 42.11, 48.17, 45.24, 41.01, 38.63, 42.21)),
.Names = c("Clay", "Silt","Sand"), row.names = c(NA, -16L), class = "data.frame")
base + geom_point(data=df,size=3)
产生以下内容:
我有一些实验数据,想绘制在土壤分类三角形上以识别质地。我正在使用此处找到的三角形:
http://www.ggtern.com/2014/01/15/usda-textural-soil-classification/
我想将粘土、沙子和淤泥显示为点。
这是我的数据:
structure(list(Clay = c(1.67, 1.29, 1.1, 1.57, 1.52, 1.72, 1.53,
1.47, 1.34, 0.84, 1.18, 1.03, 1.1, 1.08, 1.41, 1.17), Silt = c(59.21,
59.39, 54.4, 57.65, 58.42, 60.17, 64.98, 60.67, 57.84, 55.73,
56.7, 50.8, 53.68, 57.92, 59.97, 56.62), Sand = c(39.09, 39.33,
44.5, 40.79, 40.04, 38.08, 33.47, 37.89, 40.81, 43.44, 42.11,
48.17, 45.24, 41.01, 38.63, 42.21)), .Names = c("Clay", "Silt",
"Sand"), row.names = c(NA, -16L), class = "data.frame")
感谢您的建议。 AT.
很抱歉 CRAN 删除了我的包,我才刚刚发现并会在有时间的时候解决这个问题,在此期间源仍然可用 HERE。
无论如何,您的解决方案很容易实现,将颜色和填充的 'aesthetic' 定义从 'global' 定义移动到仅特定于 geom_polygon(。 ..),如下所示:
让我们从(略微)修改的美国农业部分类开始,取自您问题中的 link:
# Load the required libraries
library(ggtern)
library(plyr)
library(grid)
# Load the Data. (Available in ggtern 1.0.3.0 next version)
data(USDA)
# Put tile labels at the midpoint of each tile.
USDA.LAB = ddply(USDA, 'Label', function(df) {
apply(df[, 1:3], 2, mean)
})
# Tweak
USDA.LAB$Angle = 0
USDA.LAB$Angle[which(USDA.LAB$Label == 'Loamy Sand')] = -35
# Construct the plot.
# NOTE aes(color=Label,fill=Label) in 3rd line below
base = ggplot(data = USDA, aes(y=Clay, x=Sand, z=Silt)) +
coord_tern(L="x",T="y",R="z") +
geom_polygon(alpha = 0.75, size = 0.5, color = 'black',aes(color=Label,fill=Label)) +
geom_text(data = USDA.LAB,
aes(label = Label, angle = Angle),
color = 'black',
size = 3.5) +
theme_rgbw() +
theme_showsecondary() +
theme_showarrows() +
custom_percent("Percent") +
theme(legend.justification = c(0, 1),
legend.position = c(0, 1),
axis.tern.padding = unit(0.15, 'npc')) +
labs(title = 'USDA Textural Classification Chart',
fill = 'Textural Class',
color = 'Textural Class')
base
现在您可以添加数据了:
df = structure(list(Clay = c(1.67, 1.29, 1.1, 1.57, 1.52, 1.72, 1.53, 1.47, 1.34, 0.84, 1.18, 1.03, 1.1, 1.08, 1.41, 1.17),
Silt = c(59.21,59.39, 54.4, 57.65, 58.42, 60.17, 64.98, 60.67, 57.84, 55.73,56.7, 50.8, 53.68, 57.92, 59.97, 56.62),
Sand = c(39.09, 39.33, 4.5, 40.79, 40.04, 38.08, 33.47, 37.89, 40.81, 43.44, 42.11, 48.17, 45.24, 41.01, 38.63, 42.21)),
.Names = c("Clay", "Silt","Sand"), row.names = c(NA, -16L), class = "data.frame")
base + geom_point(data=df,size=3)
产生以下内容: