【发布时间】:2019-01-11 15:00:42
【问题描述】:
我正在尝试使用等值线显示泻湖环境中的电导率横截面。我已将interp() 和stat_contour() 应用于我的数据,但我想剪切内插输出,使其不会超出我的数据点。这样,横断面中泻湖的水深就很清楚了。这是我目前使用的代码:
cond_df <- read_csv("salinity_profile.csv")
di <- interp(cond_df$stop, cond_df$depth, cond_df$conductivity,
xo = seq(min(cond_df$stop), max(cond_df$stop), length = 200),
yo = seq(min(cond_df$depth), max(cond_df$depth), length = 200))
dat_interp <- data.frame(expand.grid(x=di$x, y=di$y), z=c(di$z))
ggplot(dat_interp) +
aes(x=x, y=y, z=z, fill=z)+
scale_y_reverse() +
geom_tile()+
stat_contour(colour="white", size=0.25) +
scale_fill_viridis_c() +
theme_tufte(base_family="Helvetica")
这是输出:
为了帮助澄清,这里是geom_point() 图表的数据,我不希望插值层越过图表的较低点:
cond_df%>%
ggplot(mapping=aes(x=stop, y=depth, z=conductivity, fill=conductivity)) +
geom_point(aes(colour = conductivity), size = 3) +
scale_y_reverse()
【问题讨论】:
-
欢迎来到 SO。如果您提供示例数据,您可能会得到更好的帮助。查看how to make a great R reproducible example
标签: r ggplot2 interpolation contour clip