Factor order within faceted dotplot using ggplot2

后端 未结 3 1707
终归单人心
终归单人心 2020-12-08 23:47

I\'m trying to change the plotting order within facets of a faceted dotplot in ggplot2, but I can\'t get it to work. Here\'s my melted dataset:

> London.m         


        
3条回答
  •  再見小時候
    2020-12-09 00:23

    This is the best I can do with qplot. Not exactly what you asked for but closer. OOOPs I see you already figured that out.

    q <- qplot(x = count, y = reorder(country, count), data = London.melt, geom = "point", facets = medal.type ~.)
    

    Here's a dput version so others can improve:

    dput(London.melt)
    structure(list(country = structure(c(9L, 6L, 3L, 1L, 7L, 4L, 
    5L, 8L, 2L, 10L, 9L, 6L, 3L, 1L, 7L, 4L, 5L, 8L, 2L, 10L, 9L, 
    6L, 3L, 1L, 7L, 4L, 5L, 8L, 2L, 10L), .Label = c("Australia", 
    "China", "France", "Germany", "Great Britain & N. Ireland", "Italy", 
    "Japan", "Russian Federation", "South Korea", "United States"
    ), class = "factor"), medal.type = structure(c(2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("bronze", 
    "gold", "silver"), class = "factor"), count = c(13L, 8L, 11L, 
    7L, 7L, 11L, 29L, 24L, 38L, 46L, 8L, 9L, 11L, 16L, 14L, 19L, 
    17L, 26L, 27L, 29L, 7L, 11L, 12L, 12L, 17L, 14L, 19L, 32L, 23L, 
    29L)), .Names = c("country", "medal.type", "count"), class = "data.frame", row.names = c("1", 
    "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
    "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", 
    "25", "26", "27", "28", "29", "30"))
    

提交回复
热议问题