教程:R可视乎|等高线图
真的是一篇很棒的教程。太详细了


#所需的包
library(reshape2) #数据处理相关
library(ggplot2) # 绘图相关
library(grDevices) #绘图颜色相关
library(RColorBrewer)#绘图颜色相关
library(directlabels) #等高线相关
接下来文章中用了一个数据集

我觉得自己重新做一个就行,

结果做出来和人家的效果真的是
可能是我的数据不太行
先说代码
ggplot(map,aes(x=Var1,y=Var2,z=value))+
geom_tile(aes(fill=value))+
scale_fill_gradientn(colours=colormap)
人家的图

我的图

有点迷人
ggplot(map,aes(x=Var1,y=Var2,z=value))+
geom_tile(aes(fill=value))+#根据高度填充
scale_fill_gradientn(colours=colormap)+
geom_contour(breaks=breaks_lines,color="black")+#
labs(x="X-Axis",y="Y-Axis",fill="Z-Value")


Contour <- ggplot(map,aes(x=Var1,y=Var2,z=value))+
geom_tile(aes(fill=value))+#根据高度填充
scale_fill_gradientn(colours=colormap)+
geom_contour(breaks=breaks_lines,color="black")+#
labs(x="X-Axis",y="Y-Axis",fill="Z-Value")+
theme(https://mmbiz.qpic.cn/mmbiz_png/MIcgkkEyTHiaGibOuExkTzniaWQLfjabNff74fgywKPFBWh2bCPbbia60icU8lnrcQiaDG3iaY8vPrxsT6qLlQKlghcYw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1
axis.title = element_text(size=15,face="plain",color="black"),
axis.text = element_text(size=13,face="plain",color="black"),
legend.title = element_text(size=13,face="plain",color="black"),
legend.text = element_text(size=11,face="plain",color="black"),
legend.background = element_blank(),
legend.position = c(0.15,0.2)
)
Contour


direct.label(Contour, list("bottom.pieces", cex=0.8,
fontface="plain", fontfamily="serif", colour='black'))

然而我的报错了
> direct.label(Contour, list("bottom.pieces", cex=0.8,
+ fontface="plain", fontfamily="serif", colour='black'))
Error in split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) :
group length is 0 but data length > 0
In addition: Warning message:
Ignoring unknown aesthetics: fill
>
咱也不是很明白为什么
记录一次吧
网友评论