在ggplot2中手动指定刻度标签 [英] Manually specify the tick labels in ggplot2

查看:64
本文介绍了在ggplot2中手动指定刻度标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ggplot2中,我有一个图,其y轴在log10(x + 1)上.我还没有找到直接指定给ggplot2使用log10(x + 1)比例尺的方法,因此我想直接修改y轴刻度标签,以代替"0、0.5、1、1.5和2"",这些刻度将显示为"0、3.2、10、32、100".有没有简单的方法可以做到这一点?

In ggplot2, I have a graph whose y-axis is on a log10(x+1). I have not found a way of specifying directly to ggplot2 to use a log10(x+1) scale, so I would like to modify the y-axis tick labels directly so that instead of "0, 0.5, 1, 1.5, and 2" these ticks would read "0, 3.2, 10, 32, 100". Is there an easy way of doing this?

代码:

  ibero.all <- ggplot(melted.LOG.Ibero, aes(colour=cultures, x = factor(Laplace, levels=c("B", "G", "T", "Bc", "PD.LD", "DT6", "DT1.5.7.8", "Gm1", "Gm2.8", "F", "P", "L.R", "A", "D", "Dv")), y = Frequency)) + 
  geom_point(position = position_dodge(width = 0.4))+
  scale_color_manual(name="", values=group.colors.Ibero)+
  ylim(0, 2)+
  labs(y = "Percentage of the toolkit", x="Typed tool classes (Laplace 1964)")+
  ggtitle("Madeleine clones of sample size 100, tool frequencies (log scale)")+
  theme(plot.title = element_text(hjust = 0.5))

我只想更改刻度标签,使它们看起来像这样:

I would like to change just the tick labels to make them look like this:

推荐答案

您将必须手动将标签输入到log10中断.

You will have to manually feed labels to your log10 breaks.

scale_y_continuous(breaks = log10(c(0, 3.2, 10, 32, 100),
                   labels = c(0, 3.2, 10, 32, 100))

现在,请注意,您正在产生误导性做法:轴中断将转换为log10(x),而不转换为log10(x + 1).您的轴不在与标绘值相同的测量比例上.

Now, please note that you are incurring in a misleading practice: The axis breaks are transformed to log10(x) and not to log10 (x + 1). Your axis is not on the same measurement scale than your plotted values.

这篇关于在ggplot2中手动指定刻度标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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