简体   繁体   English

更改 ggplot 中的 y 轴文本

[英]Change y axis text in ggplot

I have the following dataset I would like to plot.我有以下数据集,我想 plot。

library(tidyverse)
df <- data.frame(first=c(40,40,40),second=c(40,80,160),third=c(40,160,640), ID=c("ID1","ID2","ID3")) %>% pivot_longer(cols=-ID)

I am using:我在用:

ggplot(df2, aes(x=name, y=value, group=ID)) +
  geom_line() +
  geom_point(size=4)

Currently, I have:目前,我有: 在此处输入图像描述

Is there a way to change the values shown on the y axis:有没有办法改变 y 轴上显示的值:

1:40
1:80
1:160
1:320
1:640

Basically, I am writing a string for the continues numeric values on y基本上,我正在为 y 上的连续数值编写一个字符串

You can set the breaks= and label= parameters to change your y-axis labels您可以设置breaks=label=参数来更改y-axis标签

ggplot(df, aes(x=name, y=value, group=ID)) +
  geom_line() +
  geom_point(size=4) + 
  scale_y_continuous(breaks=c(40,80,160,320,640), label=function(x) paste0("1:", x))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM