I would like to control the display of graphics using factors and facets.
I have consulted many sources to get where I am, but I cannot piece together the information to solve the final issues with the graph I'm producing.
I would specifically like to accomplish:
- Order of values from high to low within a facet
- Relabel the title of the factor legend
Sample data and code are below :
##### !!!!! graphing with factors and facets
library(ggplot2)
lm <- read.table(header=TRUE, text="
                     country| medal.type |  count | member
                 South Korea |      gold |13 | 0
                       Italy |      gold |8 | 1 
                      France |      gold |11 | 1
                   Australia |      gold |7 | 0
                       Japan |      gold |7 | 0
                     Germany |      gold |11 | 1
  Great Britain & N. Ireland |      gold |29 | 1
          Russian Federation |      gold |24 | 0
                       China |      gold |38 | 0
               United States |      gold |46 | 0
                 South Korea |    silver |8 | 0
                       Italy |    silver |9 | 1
                      France |    silver |11 | 1
                   Australia |    silver |16 | 0
                       Japan |    silver |14 | 0
                     Germany |    silver |19 | 1
  Great Britain & N. Ireland |    silver |17 | 1
          Russian Federation |    silver |26 | 0
                       China |    silver |27 | 0
               United States |    silver |29 | 0
                 South Korea |    bronze |7 | 0
                       Italy |    bronze |11 | 1
                      France |    bronze |12 | 1
                   Australia |    bronze |12 | 0
                       Japan |    bronze |17 | 0
                     Germany |    bronze |14 | 1
  Great Britain & N. Ireland |    bronze |19 | 1
          Russian Federation |    bronze |32 | 0
                       China |    bronze |23 | 0
               United States |    bronze |29 | 0
               XXXXXXX       |    bronze |12 | 0
", sep="|"  )
lm$medal.type_f <- factor(lm$medal.type, labels= c("gold","silver","bronze"))
lm$country_l <- with(lm, paste(country, medal.type, sep = "_"))
lm$member_f <- factor(lm$member , labels = c("Not EU" , "EU"))
# Make every country unique
lm$country_l <- with(lm, paste(country, medal.type, sep = "_"))
dev.new(width=12, height=8)
p <- ggplot(lm, aes(x=count , y=country , group=member_f ) )
p  + geom_point(size=3,  aes( shape=factor(member_f)))   +  
scale_shape_manual(values=c(1,19))   +  
scale_size_manual(values=c(3,3))   + 
scale_fill_manual(name="European Union\n Membership") + 
facet_grid(medal.type_f ~., scales="free" ) + geom_vline(xintercept=mean(lm$count), color="red") + 
xlab("Count of Medals")  + 
scale_y_discrete("Country", breaks = lm$country, label = lm$country) 
#####  !!!!!  end of program
I would like to order the medal count from highest to lowest within a facet and change the legend title.  I would like to indicate if a country is a member of the EU using a factor, so I used different symbols to indicate as such.  My attempt as using scale_fill_manual was unsuccessful.
The graph that is produced for me is :
Some of the references I've consulted are below :

 
     
    
