【发布时间】:2020-01-27 12:37:45
【问题描述】:
我正在绘制数据,范围在 1e15-2e15 之间,不幸的是我无法绘制一个漂亮的折线图。如何使 y 轴缩写为 1e15 而不是 1000000000000000in graph DATA Link
>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)
【问题讨论】:
-
您确定 y 轴变量没有被编码为一个因素吗?
class(test$SA)的剂量是多少? -
如果你
dput(test)会很有帮助。 -
使用
scale_y_continuous(label=scales::scientific_format()) -
您的
SA变量应该是数字,所以您应该先尝试ggplot(test,aes(x=NO2, y= as.numeric(SA))),但没有样本数据,这有点像在黑暗中拍摄。