2017-01-09 25 views
0

두 번째 패싯에서 x 축 레이블을 수정할 수 없습니다. 첫 번째 패싯의 경우는 괜찮지 만 두 번째 패싯의 패싯을 만드는 방법은 119, 121, 130, 133?facet_grid : 각 패싯의 x 축 레이블 수정

My figure with the incorrect x axis labels for the second facet

여기 내 코드입니다 : 내가 완전한 R 초보자입니다 https://www.dropbox.com/s/kppvgucdwa20otd/data.csv?dl=0

이 내 첫 인물 중 하나입니다 :

data$treatment <- factor(data$treatment, levels = c("baseline", "3m")) 
labels<- c(`baseline` = "Baseline",`3m` = "3 m after") 

p <- ggplot(data = data, aes(x = day, y = BL.P, group = mechanism)) + 
geom_line(aes(color = mechanism), size = 1) + 
geom_point(aes(color = mechanism), size = 3) + 
scale_color_manual(values = c("#CC79A7", "#0072B2", "#000000"), 
        name = "Mechanism") + 
labs(title = "Title", x = "Day", y = "Proportion (%)") + 


p + facet_grid(~treatment, scales = "free_x", space = "free_x", 
       labeller = labeller(treatment = labels)) + 
    scale_x_continuous(breaks = seq(1,21,by = 1), 
         labels = c("1","3","5","8","10","15","17","19","22","24", 
            "26","29","31","33","36","38","40","43","45", 
            "47","50")) + 
    theme(strip.text.x = element_text(size = 12, face = "bold"))  

가 여기 내 데이터입니다. 나는 매우 여기에 그것을 할 수있는 한 빠른 & 더러운 방법입니다

답변

0

... 간단한 해결책 가능하면 감사하겠습니다 (이있을 수 있습니다 더 나은 옵션) :

library(ggplot2) 
download.file("https://www.dropbox.com/s/kppvgucdwa20otd/data.csv?dl=1", tf <- tempfile(fileext = ".csv")) 
data <- read.csv(tf) 
data$treatment <- factor(data$treatment, levels = c("baseline", "3m")) 
labels<- c(`baseline`="Baseline",`3m`="3 m after") 

data2 <- data 
data2$day[data2$treatment=="3m"] <- c("1"="119","3"="121","5"="130","8"="133")[data2$day[data2$treatment=="3m"]] 
data2$day[data2$treatment=="baseline"] <- structure(c("1", "3", "5", "8", "10", "15", "17", "19", "22", 
"24", "26", "29", "31", "33", "36", "38", "40", "43", "45", "47", 
"50"), .Names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", 
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", 
"21"))[data2$day[data2$treatment=="baseline"]] 
data2$day <- factor(data2$day, levels = sort(as.numeric(unique(data2$day)))) 

ggplot(data=data2, aes(x=day, y=BL.P, group=mechanism)) + 
    geom_line(aes(color=mechanism), size=1)+ 
    geom_point(aes(color=mechanism), size=3)+ 
    scale_color_manual(values=c("#CC79A7", "#0072B2", "#000000"), name="Mechanism")+ 
    labs(title="Title",x="Day", y = "Proportion (%)") + 
    facet_grid(~treatment, scales = "free_x", space = "free_x",labeller=labeller(treatment = labels)) + 
    theme(strip.text.x = element_text(size=12, face="bold"))