我有一個刻面ggplot
像這樣:在ggplot面軸小數的智能號標籤
library(ggplot2)
grid <- seq(-10,10,length.out=1000)
df <- data.frame(x=rep(grid,2),y=c(grid^2,100+grid^2/100000000),group=rep(c(1,2),each=length(grid)))
ggplot(df,aes(x,y)) + geom_line() + facet_wrap(~group,scales='free')
問題是,對於組2中的y軸的值都是相同的,因爲它們只在6-7th不同小數。所以我試了
fmt <- function(){
function(x) format(x,nsmall = 7,scientific = FALSE)
}
ggplot(df,aes(x,y)) + geom_line() + facet_wrap(~group,scales='free') + scale_y_continuous(labels = fmt())
但是,第一組(duh!)增加了很多不必要的小數。
有沒有什麼辦法讓ggplot
顯示然而,許多小數位數所必需的所有在y軸上的值各方面有所不同?或者是在gridExtra
這裏我最好的選擇呢?
我想這是類似的,但可能不相同:http://stackoverflow.com/questions/11585954/varying-axis-labels-formatter-每個小功能於ggplot-R – RoyalTS