R 使用ggplot或spplot绘制值,如1.10e15、1.3e15、2e15

R 使用ggplot或spplot绘制值,如1.10e15、1.3e15、2e15,r,excel,ggplot2,plot,R,Excel,Ggplot2,Plot,我正在尝试绘制1e15-2e15之间的数据,不幸的是,我无法绘制一个漂亮的线图。如何使y轴在图中缩写为1e15而不是10000000000000 您确定y轴变量未被编码为因子吗?classtest$SA给出了什么剂量?如果您使用dputtest.use scale_y_continuouslabel=scales::scientific_format您的SA变量应该是数字的,所以您应该首先尝试ggplottest,aesx=NO2,y=as.numericSA,但没有样本数据,这有点像是在黑暗中

我正在尝试绘制1e15-2e15之间的数据,不幸的是,我无法绘制一个漂亮的线图。如何使y轴在图中缩写为1e15而不是10000000000000


您确定y轴变量未被编码为因子吗?classtest$SA给出了什么剂量?如果您使用dputtest.use scale_y_continuouslabel=scales::scientific_format您的SA变量应该是数字的,所以您应该首先尝试ggplottest,aesx=NO2,y=as.numericSA,但没有样本数据,这有点像是在黑暗中拍摄的。
>library(readxl)
>library("xlsx")
>library(ggplot2)
>test <- read.xlsx2("/filepath/test.xlsx", 1, header=TRUE)  
>ggplot(test,aes(x=NO2, y=  SA)) + geom_point()
>class(test$SA)
[1] "factor"
> dput(test)
structure(list(NO2 = structure(1:11, .Label = c("2008", "2009", 
"2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", 
"2018"), class = "factor"), Bangladesh = structure(c(1L, 4L, 
3L, 6L, 7L, 2L, 9L, 5L, 8L, 10L, 11L), .Label = c("1927189454271550", 

> scientific <- function(x) {
    parse(text=gsub("e", " %*% 10^", scales::scientific_format()(x)))
  }
> ggplot(test,aes(x=NO2, y=  SA)) + geom_point() +scale_y_continuous(label=scientific)
Error: Discrete value supplied to continuous scale
> ggplot(test,aes(x=NO2, y=  SA)) + geom_point() +scale_y_continuous(label=scales::scientific_format())
Error: Discrete value supplied to continuous scale
>ggplot(test,aes(x=NO2, y= as.numeric(SA)))+scale_y_continuous(label=scientific_10)
> test$SA=as.numeric(levels(test$SA))[test$SA]
> ggplot(test,aes(x=NO2, y=  SA)) + geom_point() +scale_y_continuous(label=scales::scientific_format())