簡體   English   中英

R ggplot2 y軸刻度

[英]R ggplot2 y-axis scale

我試圖更改y軸比例范圍。
我使用代碼設置y比例尺:

coord_cartesian(ylim = c(min(value) - 0.05, max(value) + 0.05))

其中value是一個數字列。
我想從最小的y軸示出value減去0.05到最大的value0.05與的斷裂0.05
但是, coord_cartesian()不起作用。 或者,我嘗試了scale_y_continuous(breaks(min(value) - 0.05, max(value) + 0.05, 0.05)) ,它也不起作用。

如何編輯我的代碼?

在此處輸入圖片說明

編輯:原始方法使用coord_cartesian ,但要指定中斷將需要scale_y_continuous

# Making fake data with similar range
mtcars$wt = mtcars$wt/6 + 0.7

ggplot(mtcars, aes(mpg, wt)) + 
  geom_point() +
  scale_y_continuous(breaks = 0.05*0:1000,
                     expand = expand_scale(add = 0.06)) # adjust to taste

在此處輸入圖片說明

你可以使用ylim()

library(ggplot2)
data(mtcars)

ggplot(data = mtcars,
       aes(x = hp,
           y = mpg,
           color = cyl
           )
       ) +
  geom_point() +
  ylim(min(mtcars$mpg) - 0.05, max(mtcars$mpg) + 0.05) 

編輯:我忘了合並max(value) + 1組件,現在包括了

嘗試這個:

+ scale_y_continuous(breaks = seq(min(value) - 0.05, max(value) + 0.05, by = 0.05))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM