[英]R Error: Discrete value supplied to continuous scale
下面的繪圖代碼給出了錯誤:提供給連續比例的離散值
我已經嘗試過堆棧溢出社區提到的這個解決方案,但它們都不起作用。 我不知道這段代碼有什么問題。
這段代碼有什么問題?
#Library Download
library(ggplot2)
library(dplyr)
library(ggthemes)
#Setting Working Directory
setwd("")
getwd()
#Main Code
data <- read.csv("Test2.csv",header=TRUE)
str(data)
xd <-factor(data$SampleID)
g <- ggplot()
g <- g + geom_bar(data= data,aes(x = xd, y = Average.of.Result,group=Element,color=Element),stat='identity',
position="dodge",
na.rm = FALSE,
show.legend = NA,
fill = rgb(0, 0, 0.8)
)+
theme_minimal(base_size = 12, base_family ="Segoe UI")+
geom_line(data=data,aes(x=xd,y=X10xDL,group=Element), size=1.25,color="blue",linetype = "dashed")+
geom_line(data=data,aes(x=xd,y=Expected.Value,group=Element), size=1.25,color="red",linetype = "dashed") +
theme_minimal(base_size = 12, base_family ="Segoe UI")
g
附在此處的數據集
有什么幫助???
您的最后一個 geom_line 使用y
的Expected.Value
的邏輯(又名布爾)值,而其他y
變量是數字。 您可以將該行替換為y = as.numeric(Expected.Value)
,這樣 TRUE 將變為 1 和 FALSE 0,可以繪制在連續軸上。
ggplot(data = mutate(mtcars, am_logi = am == 1)) +
geom_line(aes(x = wt, y = mpg)) +
# geom_point(aes(x = wt, y = am_logi)) + # ERROR
geom_point(aes(x = wt, y = as.numeric(am_logi))) # NO ERROR
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.