ggplot2绘图学习 控制坐标轴的范围

之前我们学习了ggplot绘制单变量,两个连续变量的图形,两个离散型变量。一个离散型变量,一个连续型变量:包括箱图,点图等等

• geom_boxplot() for box plot
• geom_violin() for violin plot
• geom_dotplot() for dot plot
• geom_jitter() for stripchart
• geom_line() for line plot
• geom_bar() for bar plot

先画个散点图

library(ggplot2)data(cars)p <- ggplot(cars, aes(x = speed, y = dist)) + geom_point()print(p)

这里默认展示了所有数据

规定X,Y轴的范围

p + coord_cartesian(xlim =c(5, 20), ylim = c(0, 50))

这里我们设置了Y轴展示0-50的数据,X轴展示5-20范围的数据

expand_limits()函数可以实现同样的功能

p + expand_limits(x = 0, y=0)

 

scale_x_continuous() 和 scale_y_continuous()函数可以设置坐标轴label和范围

p + scale_x_continuous(name="Speed of cars", limits=c(0, 30)) +  scale_y_continuous(name="Stopping distance", limits=c(0, 150))

 

生物信息学

ggplot2绘图学习 调整线的类型

2020-8-10 21:21:11

生物信息学

R tips:使用{}自由的使用管道

2020-8-11 22:11:33

声明 本网站部分文章源于互联网,出于传递更多信息和学习之目的转载,并不保证内容正确或赞同其观点。
如转载稿涉及失效、版权等问题,请立即联系管理员;我们会予以修改、删除相关文章,请留言反馈
Notice: When your legal rights are being violated, please send an email to: [email protected].
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索