Guys I'm trying to plot Value vs Location of my dataframe called gdp , the thing is that GGPLOT2 is not using my presorted column (with as.factor) and it's just plotting in the same way that the original indexes of the dataframe place the rows. My idea is to plot with an ascendent sorting of gdp$Values , please help.
head(gdp)
LOCATION INDICATOR SUBJECT MEASURE FREQUENCY TIME Value Flag Codes
33 GRC EDUPUBEXP PRY_NTRY PC_GDP A 2014 M
5 CZE EDUPUBEXP PRY_NTRY PC_GDP A 2014 2.409
29 CHL EDUPUBEXP PRY_NTRY PC_GDP A 2014 2.473
34 TUR EDUPUBEXP PRY_NTRY PC_GDP A 2014 2.56
23 SVK EDUPUBEXP PRY_NTRY PC_GDP A 2014 2.575
24 ESP EDUPUBEXP PRY_NTRY PC_GDP A 2014 2.641
gdp$Value <- factor(gdp$Value , levels = gdp$Value )
ggplot(gdp, aes(LOCATION,Value,fill=LOCATION)) + geom_bar(stat="identity")
Update : Reproducible Example
structure(list(LOCATION = c("DNK", "NOR", "ISL", "BEL", "GBR",
"PRT", "FIN", "ISR", "NZL", "SWE"), INDICATOR = c("EDUPUBEXP",
"EDUPUBEXP", "EDUPUBEXP", "EDUPUBEXP", "EDUPUBEXP", "EDUPUBEXP",
"EDUPUBEXP", "EDUPUBEXP", "EDUPUBEXP", "EDUPUBEXP"), SUBJECT = c("PRY_NTRY",
"PRY_NTRY", "PRY_NTRY", "PRY_NTRY", "PRY_NTRY", "PRY_NTRY", "PRY_NTRY",
"PRY_NTRY", "PRY_NTRY", "PRY_NTRY"), MEASURE = c("PC_GDP", "PC_GDP",
"PC_GDP", "PC_GDP", "PC_GDP", "PC_GDP", "PC_GDP", "PC_GDP", "PC_GDP",
"PC_GDP"), FREQUENCY = c("A", "A", "A", "A", "A", "A", "A", "A",
"A", "A"), TIME = c(2014L, 2014L, 2014L, 2014L, 2014L, 2014L,
2014L, 2014L, 2014L, 2014L), Value = c("4.684", "4.51", "4.491",
"4.229", "4.218", "3.993", "3.919", "3.859", "3.811", "3.68"),
`Flag Codes` = c("", "", "", "", "", "", "", "", "", "")), .Names = c("LOCATION",
"INDICATOR", "SUBJECT", "MEASURE", "FREQUENCY", "TIME", "Value",
"Flag Codes"), row.names = c(6L, 20L, 11L, 3L, 27L, 22L, 7L,
31L, 19L, 25L), class = "data.frame")
I'm using dplyr,ggplot2 and jsonlite as libraries.
Output of sessioninfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Chile.1252 LC_CTYPE=Spanish_Chile.1252
[3] LC_MONETARY=Spanish_Chile.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Chile.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] jsonlite_1.5 ggplot2_2.2.1 dplyr_0.7.4 readxl_1.0.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 digest_0.6.15 assertthat_0.2.0
[4] plyr_1.8.4 grid_3.4.4 cellranger_1.1.0
[7] R6_2.2.2 gtable_0.2.0 magrittr_1.5
[10] scales_0.5.0 pillar_1.2.1 rlang_0.2.0
[13] lazyeval_0.2.1 bindrcpp_0.2.2 labeling_0.3
[16] tools_3.4.4 glue_1.2.0 munsell_0.4.3
[19] compiler_3.4.4 colorspace_1.3-2 pkgconfig_2.0.1
[22] bindr_0.1.1 tibble_1.4.2 R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Chile.1252 LC_CTYPE=Spanish_Chile.1252
[3] LC_MONETARY=Spanish_Chile.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Chile.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] jsonlite_1.5 ggplot2_2.2.1 dplyr_0.7.4 readxl_1.0.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 digest_0.6.15 assertthat_0.2.0
[4] plyr_1.8.4 grid_3.4.4 cellranger_1.1.0
[7] R6_2.2.2 gtable_0.2.0 magrittr_1.5
[10] scales_0.5.0 pillar_1.2.1 rlang_0.2.0
[13] lazyeval_0.2.1 bindrcpp_0.2.2 labeling_0.3
[16] tools_3.4.4 glue_1.2.0 munsell_0.4.3
[19] compiler_3.4.4 colorspace_1.3-2 pkgconfig_2.0.1
[22] bindr_0.1.1 tibble_1.4.2