我在ggplot2中的文本替换和格式化方面有点困难。这是我的剧本:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
library(extrafont)
font_import(pattern = 'Arch')
library(ggplot2)
library(RColorBrewer)
df <- read.csv("https://dl.dropboxusercontent.com/u/73950/moduVSmnc.csv")
breaks1 <- seq(1.85,2.5,by=0.05)
gg <- aggregate(mnc~cut(apl,breaks=breaks1,
labels=format(breaks1[-1],nsmall=2))+modu,df,mean)
colnames(gg)<- c("apl","modu","mnc")
gg$modu <- as.factor(gg$modu)
ggplot(gg) +
geom_tile(aes(x=modu,y=apl,fill=mnc))+
scale_fill_gradientn(colours=rev(brewer.pal(10,"Spectral"))) +
coord_fixed()+
theme(legend.position = "right", axis.ticks = element_blank(),
axis.text.x = element_text(size = 10, angle = 90, vjust = 0.25 , hjust = 1, colour = "grey50", family="Archer-Medium")
,axis.text.y = element_text(size = 10, angle = 0, hjust = 1, colour = "grey50", family="Archer-Medium"))
产生这个情节:
现在:
另外,
谢谢!
答案 0 :(得分:4)
所以,多亏了这里和那里聚集的评论者和点点滴滴,我设法得到了我想要的东西。
这是脚本:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
library(extrafont)
font_import(pattern = 'Arch')
library(ggplot2)
library(RColorBrewer)
df <- read.csv("https://dl.dropboxusercontent.com/u/73950/moduVSmnc.csv")
breaks1 <- seq(1.85,2.5,by=0.05)
gg <- aggregate(mnc~cut(apl,breaks=breaks1,
labels=format(breaks1[-1],nsmall=2))+modu,df,mean)
colnames(gg)<- c("apl","modu","mnc")
gg$modu <- as.factor(gg$modu)
ggplot(gg) +
geom_tile(aes(x=modu,y=apl,fill=mnc))+ labs(x="A", y="B", fill="C") +
theme(axis.title.x = element_text(vjust = 0 , family="Archer-Semibold", colour="grey25", size=12),
axis.title.y = element_text(vjust = 1 , family="Archer-Semibold", colour="grey25", size=12),
legend.title = element_text(vjust = 1 , family="Archer-Semibold", colour="grey25", size=12),
legend.text = element_text(vjust = 1 , family="Archer-Semibold", colour="grey25", size=12)) +
scale_fill_gradientn(colours=rev(brewer.pal(10,"Spectral"))) +
coord_fixed()+
theme(legend.position = "right", axis.ticks = element_blank(),
axis.text.x = element_text(size = 10, angle = 90, vjust = 0.25 , hjust = 1, colour = "grey50", family="Archer-Medium")
,axis.text.y = element_text(size = 10, angle = 0, hjust = 1, colour = "grey50", family="Archer-Medium"))
谢谢!