plot(x, y) # 未作处理 plot(x, y, xaxs = "i", yaxs ="i") # 绘图边框未留白 plot(x, y, bty = 'l') # 只保留左和下两条边框 plot(x, y, ann = F, bty = "n", xaxt = "n", yaxt = "n") # 边框、坐标轴都去掉 1. 2. 3. 4. 5. 6. 7. axis函数 x <- seq(-4...
names_to="x",values_to="y")%>%mutate(x=as.numeric(x))%>%ggplot(aes(x,y))+geom_line(aes(group=rowname,color=rowname))+scale_x_reverse()
options(repr.plot.width = 5, repr.plot.height = 15, repr.plot.res = 300) # 默认位置标度scale_x_continuous()和scale_y_continuous() p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point() + scale_x_continuous() + scale_y_continuous() #x轴刻度颠倒scale_x_reverse() p2 <- p1 + sca...
plot(ur,axes=FALSE, xlab="", ylab="", col="red", type="b") # 右侧加上纵轴 mtext("UR(%)", 4, 3) axis(4) 双坐标图 42. R 语言如何用不同的颜色来代表数据? 对于类似于barplot()高级绘图函数,可使用col参数设置。 x <- 1:10 names(x) <- letters[1:10] barplot(x, col=rev(heat...
position_stack(vjust =1, reverse =FALSE) position_dodge(width=NULL) position_fill(vjust=1, reverse = FALSE) 本文使用vcd包中的Arthritis数据集来演示如何创建条形图。 head(Arthritis) ID Treatment Sex Age Improved157Treated Male27Some246Treated Male29None377Treated Male30None417Treated Male32Marked536...
position_stack(vjust =1, reverse =FALSE) position_dodge(width=NULL) position_fill(vjust=1, reverse = FALSE) 本文使用vcd包中的Arthritis数据集来演示如何创建条形图。 head(Arthritis) ID Treatment Sex Age Improved157Treated Male27Some246Treated Male29None377Treated Male30None417Treated Male32Marked536...
在上面的代码中,我们首先创建了一个简单的数据集x和y,然后使用plot()函数绘制了折线图。最后使用axis()函数调整了Y轴的刻度,使刻度范围在0到100之间,间隔为20,并添加了百分号标签。 使用示例 接下来,我们将使用一个旅行图和一个甘特图来演示如何在R语言中调整Y轴刻度。
plotbp<-ggplot(PlantGrowth,aes(x=group,y=weight))+geom_boxplot()bp# Horizontal box plotbp+coord_flip()set.seed(1234)# Basic histogramhp<-qplot(x=rnorm(200),geom="histogram")hp# Horizontal histogramhp+coord_flip()# Reverse y axis# Basic histogramhp# Y axis reversedhp+scale_y_reverse(...
dp+scale_x_date(breaks=date_breaks("months"),labels=date_format("%b"))head(economics)# Plotwithdates dp<-ggplot(data=economics,aes(x=date,y=psavert))+geom_line()dp # Axis limitsc(min,max)min<-as.Date("2002-1-1")max<-max(economics$date)dp+scale_x_date(limits=c(min,max))...
fill='lightblue')+labs(x='',y='')+scale_x_reverse(expand=c(0,0),limits=c(30,0))+scale_y_discrete(position='right')+theme_void()+ggtitle('男性人口分布')+theme(plot.title=element_text(hjust=0.5))+theme(axis.text.y=element_blank())+geom_text(aes(x=n+2,y=age_group,label=n)...