增加轴刻度的数量 [英] Increase number of axis ticks

查看:162
本文介绍了增加轴刻度的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为某些数据生成了图表,但滴答数量太少,我在阅读时需要更多的精确度

有什么方法可以增加ggplot2中的坐标轴数量?



我知道我可以告诉ggplot使用矢量作为坐标轴,但我想要的是为所有数据增加滴答数。换句话说,我想从数据中计算出剔号。



可能ggplot在内部用一些算法来做这件事,但我找不到它是如何做到的,可以根据我想要的进行更改。

/ code>和/或 scale_y_continuous 。例如:

  library(ggplot2)
dat < - data.frame(x = rnorm(100), y = rnorm(100))

ggplot(dat,aes(x,y))+
geom_point()

给你:


重写比例可以给你这样的东西:

  ggplot(dat,aes(x,y))+ 
geom_point()+
scale_x_continuous(breaks = round(seq(min(dat $ x) ,1))+
scale_y_continuous(break = round(seq(min(dat $ y),max(dat $ y),by = 0.5),1)max(dat $ x) )


如果你想简单地放大一个图的特定部分,看看 xlim() ylim()。您也可以在了解其他参数。


I'm generating plots for some data, but the number of ticks is too small, I need more precision on the reading.

Is there some way to increase the number of axis ticks in ggplot2?

I know I can tell ggplot to use a vector as axis ticks, but what I want is to increase the number of ticks, for all data. In other words, I want the tick number to be calculated from the data.

Possibly ggplot do this internally with some algorithm, but I couldn't find how it does it, to change according to what I want.

解决方案

You can override ggplots default scales by modifying scale_x_continuous and/or scale_y_continuous. For example:

library(ggplot2)
dat <- data.frame(x = rnorm(100), y = rnorm(100))

ggplot(dat, aes(x,y)) +
  geom_point()

Gives you this:

And overriding the scales can give you something like this:

ggplot(dat, aes(x,y)) +
  geom_point() +
  scale_x_continuous(breaks = round(seq(min(dat$x), max(dat$x), by = 0.5),1)) +
  scale_y_continuous(breaks = round(seq(min(dat$y), max(dat$y), by = 0.5),1))

If you want to simply "zoom" in on a specific part of a plot, look at xlim() and ylim() respectively. Good insight can also be found here to understand the other arguments as well.

这篇关于增加轴刻度的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆