【问题标题】:Use different length of ticks in one ggplot graph在一个 ggplot 图中使用不同长度的刻度
【发布时间】:2023-03-19 00:26:01
【问题描述】:

我想在一个 ggplot 图中应用不同长度的刻度,如下所示: enter image description here

我尝试使用

scale_x_continuous(breaks = c(seq(0,1, by = 0.1),seq(1,5,1)))

自定义刻度,但这只会给出不同的步长。 有什么建议? enter image description here

抱歉,图片是作为链接附加的。

【问题讨论】:

  • 请提供可重现的数据和代码

标签: r ggplot2


【解决方案1】:

您所观察的是记录 x 比例的效果。

library(dplyr)
library(ggplot2)
library(readr)

"x,y
0.09838589987314314, 431.84212280818747
0.19646546437091444, 1072.2954863657576
0.29750771557320366, 1347.2844856323754
0.3955242765781446, 1546.716447763184
0.49672163253953483, 1501.5827721848123
0.5940891079858363, 1320.5680378691911
0.6990737071572558, 1178.7879191946129
0.7962694810692876, 1061.1374091606106
0.8923393306748771, 919.3252883525568
0.9838589987314309, 831.8421228081871
1.1025615087338325, 744.3696246416428
1.1863284538600922, 678.0025335022334
1.286887658830817, 599.5653043536236
1.3959707710478373, 554.3356223748249
1.4898579966508398, 509.09527301820117
1.6030497343115249, 454.80365357690516
1.6696092455367386, 403.50956730448706
1.7674609336378837, 376.37709180612046
1.886333052497789, 346.2310820721382
1.9968863894545188, 322.11747449829977
2.079798216336457, 291.9554636975797
2.31183906016707, 255.79838655910407
2.5078022414885948, 213.5875725048336
2.6764666574617317, 192.49816654443634
2.9033375196831206, 162.36282418827932
3.0238856986296256, 153.3328888592573
3.149439104611845, 144.3029535302353
3.3340199781197377, 132.26481765451013
3.500818628686328, 117.20248016534447
3.6759620972244393, 111.19674644976362
3.7975657368770896, 99.14260950730068
3.923192118001404, 96.14507633842254
4.086085223703413, 96.17174478298557
4.616479953856948, 78.13854256950458
5.089953102964006, 63.10820721381424
5.61198637258845, 57.13447563170894
6.038356194859665, 51.14474298286564
6.712049082852011, 42.15747716514443
6.990737071572554, 33.12754183612242
7.521857271241964, 36.194412960864156
8.093329248357565, 27.185812387492433
8.226106849449925, 27.19647976531769
8.498232760057107, 27.217814520968204
8.85108408255861, 24.22561504100281
9.446371423329051, 24.268284552303612" %>% 
  read_csv() %>% 
  ggplot(aes(x, y)) + 
  geom_point() + 
  geom_line() + 
  scale_y_continuous(breaks = seq(0, 1600, 200)) + 
  labs(x = "Window mm", 
       y = element_blank()) -> p

p

产生这个:

但如果我们记录 x 比例:

p + 
  scale_x_log10(breaks = c(seq(0.1, 0.3, 0.1), seq(0.4, 0.8, 0.2), 1:10), 
                labels = c(seq(0.1, 0.3, 0.1), seq(0.4, 0.8, 0.2), 1:10))

我们得到这个:

现在您必须将其应用于您的数据。

【讨论】:

    猜你喜欢
    • 2021-11-05
    • 1970-01-01
    • 2020-11-09
    • 2017-01-15
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    相关资源
    最近更新 更多