r - Order of plots in ggplot2 facet -


>panel_data concentration statistic                               name 1            100    39.100                     cd4 subset_but 2             10    39.700                     cd4 subset_but 3              1     0.012                     cd4 subset_but 4              0    41.200                     cd4 subset_but 5            100     3.970        cd4 subset/cd103 subset_but 6             10     2.940        cd4 subset/cd103 subset_but 7              1   100.000        cd4 subset/cd103 subset_but 8              0     2.620        cd4 subset/cd103 subset_but 9            100    57.900         cd4 subset/cd39 subset_but 10            10    31.200         cd4 subset/cd39 subset_but 11             1     0.000         cd4 subset/cd39 subset_but 12             0    30.600         cd4 subset/cd39 subset_but 13           100     8.090         cd4 subset/cd69 subset_but 14            10     6.530         cd4 subset/cd69 subset_but 15             1   100.000         cd4 subset/cd69 subset_but 16             0     4.930         cd4 subset/cd69 subset_but 17           100    49.700         cd4 subset/cd73 subset_but 18            10    51.300         cd4 subset/cd73 subset_but 19             1    25.000         cd4 subset/cd73 subset_but 20             0    49.800         cd4 subset/cd73 subset_but 21           100     4.520  cd4 subset/integrin b7 subset_but 22            10     4.230  cd4 subset/integrin b7 subset_but 23             1    75.000  cd4 subset/integrin b7 subset_but 24             0     4.370  cd4 subset/integrin b7 subset_but 25           100    34.300                    cd8a subset_but 26            10    36.700                    cd8a subset_but 27             1     0.012                    cd8a subset_but 28             0    33.500                    cd8a subset_but 29           100     4.610       cd8a subset/cd103 subset_but 30            10     3.400       cd8a subset/cd103 subset_but 31             1    75.000       cd8a subset/cd103 subset_but 32             0     4.060       cd8a subset/cd103 subset_but 33           100    74.900        cd8a subset/cd39 subset_but 34            10    56.900        cd8a subset/cd39 subset_but 35             1     0.000        cd8a subset/cd39 subset_but 36             0    54.300        cd8a subset/cd39 subset_but 37           100     7.320        cd8a subset/cd69 subset_but 38            10     6.870        cd8a subset/cd69 subset_but 39             1     0.000        cd8a subset/cd69 subset_but 40             0     5.480        cd8a subset/cd69 subset_but 41           100    72.500        cd8a subset/cd73 subset_but 42            10    73.200        cd8a subset/cd73 subset_but 43             1     0.000        cd8a subset/cd73 subset_but 44             0    73.700        cd8a subset/cd73 subset_but 45           100    16.400 cd8a subset/integrin b7 subset_but 46            10    17.000 cd8a subset/integrin b7 subset_but 47             1     0.000 cd8a subset/integrin b7 subset_but 48             0    19.900 cd8a subset/integrin b7 subset_but 

i have plotted above data using following code:

panel_data_graph <- ggplot(panel_data,                             aes(concentration, statistic)) +   geom_point(color="black") +    facet_wrap(~ name, ncol = 3) +   xlab("concentration") +    ylab(expression("statistic")) +   geom_smooth(method=lm, se=false, fullrange=true, size = 0.4) +   theme_bw()   print(panel_data_graph) 

however, graph output following:

graph output

i want graphs ordered panel_data$name. example, top left row should cd4 subset_but, cd4 subset/cd103 subset_but, cd subset/cd39 subset_but.

for regression lines on plot shown correspond correct graph, graphs must arranged in following order:

regrdf

                                 name              lbl 1                      cd4 subset_but y = -0.358x + 40 2         cd4 subset/cd103 subset_but  y = 0.396x + 20 3          cd4 subset/cd39 subset_but y = -0.334x + 40 4          cd4 subset/cd69 subset_but y = 0.0897x + 40 5          cd4 subset/cd73 subset_but y = -0.267x + 30 6   cd4 subset/integrin b7 subset_but  y = 0.139x + 30 7                     cd8a subset_but y = -0.263x + 30 8        cd8a subset/cd103 subset_but  y = 0.412x + 40 9         cd8a subset/cd39 subset_but  y = 0.0363x + 4 10        cd8a subset/cd69 subset_but   y = 0.27x + 50 11        cd8a subset/cd73 subset_but y = 0.0471x + 10 12 cd8a subset/integrin b7 subset_but  y = 0.128x + 20 

modify data frame way

panel_data$name <- factor(panel_data$name, levels=c(order-you-want), ordered=true) 

you need set factor levels ordered=true

see reproducible example

data <- mtcars data$cyl <- factor(data$cyl, levels=c(6,4,8), ordered=true) library(ggplot2)  # unordered ggplot(data=mtcars, aes(x=carb, y=mpg, color=cyl)) +   geom_point() +   facet_wrap(~cyl, ncol=3)  # ordered ggplot(data=data, aes(x=carb, y=mpg, color=cyl)) +   geom_point() +   facet_wrap(~cyl, ncol=3) 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -