2016-07-14 1 views
1

I 두 연속 변수 (소포 세포), 2 개 개의 레벨 (HC 및 RA)와 함께 단일 그룹핑 변수로 설정하는 간단한 데이터 여기 모의 가지고그룹 내의 비선형 회귀선과 ggplot2의 총 데이터를 플롯하는 방법은 무엇입니까?

###Simulate Vesicle variable### 
Vesicle.hc <- sort(runif(23, 0.98, 5)) #HC group 
Vesicle1.ra <- sort(runif(5, 0.98, 3)) #RA group 
Vesicle <- c(Vesicle.hc, Vesicle1.ra) #Combined 

###Simulate Cells variable### 
z <- seq(23) 
Cells.hc <- (rnorm(23, 50 + 30 * z^(0.2), 8))*runif(1, 50000, 400000) #HC group 
Cells.ra <- c(8.36e6, 6.35e6, 1.287e7, 1.896e7, 1.976e7)    #RA group 
Cells <- c(Cells.hc, Cells.ra)           #Combined 

###Define groups and create dataframe### 
Group <- rep("HC",23)        #HC group 
Group1 <- rep("RA",5)        #RA Group 
Group <- c(Group, Group1)       #Combined 
df <- data.frame(Cells, Vesicle, Group)    #Data frame 

는 I 데이터의 산점도를 플롯 한

###Plot data### 
library(ggplot2) 
ggplot(df, aes(x = Cells, y = Vesicle, colour=Group)) + 
    xlab("Stimulated neutrophils") + 
    ylab("MV/cell") + 
    stat_smooth(method = 'nls', formula = 'y~a*exp(b*x)',      #Fit nls model 
       method.args = list(start=c(a=0.1646, b=9.5e-8)), se=FALSE) + #Starting values 
    geom_point(size=4, pch=21,color = "black", stroke=1.5, aes(fill=Group)) #Change point style 

질문, 각 그룹의 비 - 선형 회귀 함수 플로팅 이외에, 얼마나 수 I는 줄거리 : 개별적으로 사용하여 각 그룹에 끼워 (here를 도시) 비선형 회귀 라인, ggplot2 사용 회귀선은 에 모두 맞습니다. 데이터 즉, 데이터를 모델링하여 그룹화 변수의 기여도를 무시합니까?

+1

당신은 Cells.hc' '의 생성에 예상치 못한 기호가 있어요. 또한'z'가 어디서 생성되는지는 알 수 없습니다. –

+0

'aes (group = NULL)'과 함께'stat_smooth'를 추가한다고 생각합니다. – Axeman

+0

오, 진심으로 사과드립니다. 나는 환경에서 이러한 변수들을 이미 가지고있었습니다. 이제 편집 된 코드가 작동합니다. 나는 당신의 제안을 @Axeman으로 시도했지만 오류가 발생하지는 않았지만 음모에는 변화가 없다. – Hefin

답변

0
ggplot(df, aes(x = Cells, y = Vesicle, colour=Group)) + 
    xlab("Stimulated neutrophils") + 
    ylab("MV/cell") + 
    stat_smooth(method = 'nls', formula = 'y~a*exp(b*x)', 
       method.args = list(start=c(a=0.1646, b=9.5e-8)), se=FALSE) + 
    stat_smooth(color = 1, method = 'nls', formula = 'y~a*exp(b*x)', 
       method.args = list(start=c(a=0.1646, b=9.5e-8)), se=FALSE) + 
    geom_point(size=4, pch=21,color = "black", stroke=1.5, aes(fill=Group)) 

enter image description here

+0

아름답습니다. 따라서 "color = 1"을 추가하면 stat_smooth가 그룹 분류를 상속하는 것을 방지 할 수 있습니다. – Hefin

+0

그래, 그게 다야. 'inherit.aes' 인수도 있습니다 만, 다시 말해서'x'와'y'를 다시 정의 했으므로 그룹핑을 무력화하는 것이 더 쉽습니다. – Axeman

관련 문제