I have a dataframe where would like to calculate the
degree of a country (node) - degree of its module / standard deviation of its module.
I have calculated degree and sd of modules by
dgclust <- aggregate(clust[, 2], list(clust$modularity_class), mean)
sdclust <- aggregate(clust[, 2], list(clust$modularity_class), sd)
But I'm not sure how I can write the calculation above so that the code links dgclust and sdclust to the specific module the country belongs to? My expected output is a value for each country based on the described calculation. Any help appreciated!
Reproducible example
clust <- dput(head(clust[1:10, c(1, 5,6)]))
structure(list(Label = structure(1:6, .Label = c("Afghanistan",
"Albania", "Algeria", "Angola", "Antigua and Barbuda", "Argentina",
"Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahrain",
"Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
"Bhutan", "Bolivia (Plurinational State of)", "Bosnia and Herzegovina",
"Botswana", "Brazil", "Brunei Darussalam", "Bulgaria", "Burkina Faso",
"Burundi", "C?te d'Ivoire", "Cambodia", "Cameroon", "Canada",
"Central African Republic", "Chile", "China", "China, Hong Kong SAR",
"China, Macao SAR", "China, Taiwan Province of", "Colombia",
"Congo", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czechia",
"Democratic People's Republic of Korea", "Democratic Republic of the Congo",
"Denmark", "Dominican Republic", "Ecuador", "Egypt", "El Salvador",
"Eritrea", "Estonia", "Eswatini", "Ethiopia", "Finland", "France",
"Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada",
"Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras",
"Hungary", "India", "Indonesia", "Iran (Islamic Republic of)",
"Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan",
"Kazakhstan", "Kenya", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic",
"Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Lithuania",
"Luxembourg", "Madagascar", "Malawi", "Malaysia", "Mali", "Malta",
"Mauritania", "Mexico", "Mongolia", "Montenegro", "Morocco",
"Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Zealand",
"Nicaragua", "Niger", "Nigeria", "North Macedonia", "Norway",
"Oman", "Pakistan", "Palestine", "Panama", "Papua New Guinea",
"Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar",
"Republic of Korea", "Republic of Moldova", "Romania", "Russian Federation",
"Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines",
"Saudi Arabia", "Senegal", "Serbia", "Sierra Leone", "Singapore",
"Slovakia", "Slovenia", "Somalia", "South Africa", "Spain", "Sri Lanka",
"Sudan", "Suriname", "Sweden", "Switzerland", "Syrian Arab Republic",
"Tajikistan", "Thailand", "Timor-Leste", "Trinidad and Tobago",
"Tunisia", "Turkey", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates",
"United Kingdom of Great Britain and Northern Ireland", "United Republic of Tanzania",
"United States of America", "Uruguay", "Uzbekistan", "Venezuela (Bolivarian Republic of)",
"Viet Nam", "Yemen", "Zambia", "Zimbabwe"), class = "factor"),
Degree = c(5L, 14L, 14L, 8L, 1L, 119L), modularity_class = c(3L,
4L, 2L, 2L, 1L, 2L)), row.names = c("Afghanistan", "Albania",
"Algeria", "Angola", "Antigua and Barbuda", "Argentina"), class = "data.frame")
In base R, we can use ave to calculate (Degree - mean)/sd for each modularity_class.
clust <- transform(clust, result = ave(Degree, modularity_class,
FUN = function(x) (x - mean(x, na.rm = TRUE))/sd(x, na.rm = TRUE)))
This can be written in dplyr and data.table as well -
library(dplyr)
clust <- clust %>%
group_by(modularity_class) %>%
mutate(result = (Degree - mean(Degree, na.rm = TRUE))/sd(Degree, na.rm = TRUE))
library(data.table)
setDT(clust)[, result := (Degree - mean(Degree, na.rm = TRUE))/sd(Degree, na.rm = TRUE), modularity_class]
Related
I have a database.
I want to build a chord diagram similar to this one:
https://i.stack.imgur.com/59JcJ.png
My code:
vertices <- data.frame(name = unique(c(as.character(imports$Partner), as.character(imports$Reporter))) )
mygraph <- graph_from_data_frame( imports, vertices=vertices )
from <- match( imports$Reporter, vertices$name)
to <- match( imports$Partner, vertices$name)
ggraph(mygraph, layout = 'dendrogram', circular = TRUE)
geom_conn_bundle(data = get_con(from = from, to = to), alpha=0.2, colour="skyblue", tension = 0)
geom_node_point(aes(filter = leaf, x = x*1.05, y=y*1.05))
theme_void()
Result:
https://i.stack.imgur.com/uY2Yq.png
I searched for all kinds of settings for the chord diagram, but I didn’t find, how to make the links of the same size, and set the number of lines as an indicator of the value. Does anyone know how to create such a diagram?
data=structure(list(Reporter = c("USA", "USA", "USA", "USA", "India",
"Japan", "Japan", "USA", "Rep. of Korea", "USA", "Japan", "Japan",
"Japan", "Rep. of Korea", "USA", "USA", "USA", "China", "USA",
"USA", "Rep. of Korea", "USA", "Japan", "Japan", "Rep. of Korea",
"China", "China", "Rep. of Korea", "India", "China", "Rep. of Korea",
"USA", "Rep. of Korea", "Japan", "China", "Rep. of Korea", "India",
"China", "China", "India", "China", "China"), Partner = c("Saudi Arabia", "Canada", "Venezuela", "Mexico",
"Areas, nes", "Saudi Arabia", "United Arab Emirates", "Nigeria",
"Saudi Arabia", "Iraq", "Iran", "Qatar", "Kuwait", "United Arab Emirates",
"Angola", "Norway", "Colombia", "Oman", "United Kingdom", "Kuwait",
"Iran", "Gabon", "Indonesia", "Oman", "Kuwait", "Angola", "Iran",
"Oman", "Saudi Arabia", "Saudi Arabia", "Qatar", "Ecuador", "Indonesia",
"China", "Indonesia", "Australia", "Nigeria", "Yemen", "Fmr Sudan",
"Kuwait", "Iraq", "Viet Nam", "Iraq", "Australia", "Angola",
"United Arab Emirates", "Argentina", "Iran", "Trinidad and Tobago",
"Congo", "Yemen", "Iraq", "Viet Nam", "Australia", "Malaysia",
"Mexico", "Indonesia", "China", "Congo", "Ecuador", "Malaysia",
"Qatar", "Brunei Darussalam", "Norway"), Qty = c(69785202126, 68349221243, 68326932683,
64923669168, 57159000064, 53691639675, 52396394737, 46817696134,
38307387772, 31471382247, 25554794183, 19184268129, 18481591406,
16695296617, 16497467586, 16029110463, 15953011573, 15660839936,
14459452736, 13796910873, 11134838478, 10393629031, 10258716565,
9751327665, 9417368771, 8636634112, 7000465408, 6586187350, 5769723904,
5730211328, 5702528697, 5553458497, 5290777764, 5113191253, 4575188480,
4361612670, 3888963072, 3612423424, 3313590784, 3223781888, 3183182080,
3158472192, 3151280715, 3081015515, 3067260000, 2921931008, 2850134892,
2607684096, 2587749446, 2547349198, 2485083122, 2443798762, 2365431992,
2342513214, 2308853961, 2130664704, 1942125162, 1828376381, 1814260579,
1785874000, 1609282280, 1598901888, 1534923974, 1477843712, 1476737920,
1454356736, 1355873401, 1293729024, 1285355978, 1278701346, 1259876360,
1252518912, 1248772992, 1223383808, 1163368000, 1144188000, 1108399232,
1062041363, 1041526592, 977722731, 897418483, 877541040, 845556546,
801940467, 744316800, 739848000, 724177472, 694896000, 685405539,
672387008, 554965585, 540327751, 508204324, 4.87e+08, 457252032,
433428000, 430473920, 426744352, 408635880, 392727578, 390598528,
390189912, 389451923, 384376548, 350920922, 327039700, 285413702,
285143680, 275486240, 274015471, 264478000, 260122000, 238997756,
227806048, 204376795, 192144011, 150791409, 140634221, 135842986,
130777039, 129973032, 125115000, 124681401, 123443000, 120061792,
110795499, 106762492, 105548008, 84693986, 70275359, 57248174,
47944463, 40236018, 30783728, 18364000, 13419253, 12551365, 9631763,
5994199, 374000, 350000, 339115, 86420, 24000, 180)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -145L))
I generated multiple plots with vertical lines in each plot using the following codes:
I was wondering if there's any way to change colours and line types of each vertical lines on this codes:
library(gridExtra)
library(grid)
library(lattice)
library(ggplot2)
vertical.lines <- c(1990,1991)
df1 %>%
filter(isocode == "KOR") %>%
select(year,rgdpe, rgdpo, avh, emp, hc) %>%
tidyr::gather(predictor, value, -year)%>%
ggplot() +
geom_line(aes(year, value))+
facet_wrap(~predictor, scales = "free")+
labs(x = NULL, y = NULL, top = "Title of the Chart",
bottom = textGrob(
"Data source: World Bank",
gp = gpar(fontface = 3, fontsize = 9),
hjust = 1,x = 1))+ sapply(vertical.lines, function(xint) geom_vline(aes(xintercept = xint)))
I want to put something like
lty = c(3,1), color = c("blue","red"), lwd=c(.5,.5))
But I don't know how to apply to my code.
My data looks like to have the structure like the following
Maybe if you need, I can add more variables.
structure(list(country = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("Aruba",
"Angola", "Anguilla", "Albania", "United Arab Emirates", "Argentina",
"Armenia", "Antigua and Barbuda", "Australia", "Austria", "Azerbaijan",
"Burundi", "Belgium", "Benin", "Burkina Faso", "Bangladesh",
"Bulgaria", "Bahrain", "Bahamas", "Bosnia and Herzegovina", "Belarus",
"Belize", "Bermuda", "Bolivia (Plurinational State of)", "Brazil",
"Barbados", "Brunei Darussalam", "Bhutan", "Botswana", "Central African Republic",
"Canada", "Switzerland", "Chile", "China", "Cote d'Ivoire", "Cameroon",
"Congo, Democratic Republic", "Congo", "Colombia", "Comoros",
"Cabo Verde", "Costa Rica", "Curacao", "Cayman Islands", "Cyprus",
"Czech Republic", "Germany", "Djibouti", "Dominica", "Denmark",
"Dominican Republic", "Algeria", "Ecuador", "Egypt", "Spain",
"Estonia", "Ethiopia", "Finland", "Fiji", "France", "Gabon",
"United Kingdom", "Georgia", "Ghana", "Guinea", "Gambia", "Guinea-Bissau",
"Equatorial Guinea", "Greece", "Grenada", "Guatemala", "Guyana",
"China, Hong Kong SAR", "Honduras", "Croatia", "Haiti", "Hungary",
"Indonesia", "India", "Ireland", "Iran (Islamic Republic of)",
"Iraq", "Iceland", "Israel", "Italy", "Jamaica", "Jordan", "Japan",
"Kazakhstan", "Kenya", "Kyrgyzstan", "Cambodia", "Saint Kitts and Nevis",
"Republic of Korea", "Kuwait", "Lao People's DR", "Lebanon",
"Liberia", "Saint Lucia", "Sri Lanka", "Lesotho", "Lithuania",
"Luxembourg", "Latvia", "China, Macao SAR", "Morocco", "Republic of Moldova",
"Madagascar", "Maldives", "Mexico", "North Macedonia", "Mali",
"Malta", "Myanmar", "Montenegro", "Mongolia", "Mozambique", "Mauritania",
"Montserrat", "Mauritius", "Malawi", "Malaysia", "Namibia", "Niger",
"Nigeria", "Nicaragua", "Netherlands", "Norway", "Nepal", "New Zealand",
"Oman", "Pakistan", "Panama", "Peru", "Philippines", "Poland",
"Portugal", "Paraguay", "State of Palestine", "Qatar", "Romania",
"Russian Federation", "Rwanda", "Saudi Arabia", "Sudan", "Senegal",
"Singapore", "Sierra Leone", "El Salvador", "Serbia", "Sao Tome and Principe",
"Suriname", "Slovakia", "Slovenia", "Sweden", "Eswatini", "Sint Maarten (Dutch part)",
"Seychelles", "Syrian Arab Republic", "Turks and Caicos Islands",
"Chad", "Togo", "Thailand", "Tajikistan", "Turkmenistan", "Trinidad and Tobago",
"Tunisia", "Turkey", "Taiwan", "U.R. of Tanzania: Mainland",
"Uganda", "Ukraine", "Uruguay", "United States of America", "Uzbekistan",
"St. Vincent & Grenadines", "Venezuela (Bolivarian Republic of)",
"British Virgin Islands", "Viet Nam", "Yemen", "South Africa",
"Zambia", "Zimbabwe"), class = "factor"), isocode = c("ABW",
"ABW", "ABW", "ABW", "ABW"), year = 1990:1994, currency = structure(c(4L,
4L, 4L, 4L, 4L), .Label = c("Algerian Dinar", "Argentine Peso",
"Armenian Dram", "Aruban Guilder", "Australian Dollar", "Azerbaijanian Manat",
"Bahamian Dollar", "Bahraini Dinar", "Baht", "Balboa", "Barbados Dollar",
"Belarussian Ruble", "Belize Dollar", "Bermudian Dollar", "Bolivar Fuerte",
"Boliviano", "Brazilian Real", "Brunei Dollar", "Bulgarian Lev",
"Burundi Franc", "CFA Franc BCEAO", "CFA Franc BEAC", "Cabo Verde Escudo",
"Canadian Dollar", "Cayman Islands Dollar", "Cedi", "Chilean Peso",
"Colombian Peso", "Comoro Franc", "Convertible Marks", "Cordoba Oro",
"Costa Rican Colon", "Croatian Kuna", "Czech Koruna", "Dalasi",
"Danish Krone", "Denar", "Djibouti Franc", "Dobra", "Dominican Peso",
"Dong", "East Caribbean Dollar", "Egyptian Pound", "Ethiopian Birr",
"Euro", "Fiji Dollar", "Forint", "Franc Congolais", "Gourde",
"Guarani", "Guinea Franc", "Guyana Dollar", "Hong Kong Dollar",
"Hryvnia", "Iceland Krona", "Indian Rupee", "Iranian Rial", "Iraqi Dinar",
"Jamaican Dollar", "Jordanian Dinar", "Kenyan Shilling", "Kip",
"Kuwaiti Dinar", "Kwacha", "Kwanza", "Kyat", "Lari", "Lebanese Pound",
"Lek", "Lempira", "Leone", "Lilangeni", "Loti", "Malagasy Ariary",
"Malaysian Ringgit", "Manat", "Mauritius Rupee", "Metical", "Mexican Peso",
"Moldovan Leu", "Moroccan Dirham", "Naira", "Namibian Dollar",
"Nepalese Rupee", "Netherlands Antillian Guilder", "New Israeli Sheqel",
"New Leu", "New Taiwan Dollar", "New Turkish Lira", "New Zealand Dollar",
"Ngultrum", "Norwegian Krone", "Nuevo Sol", "Ouguiya", "Pakistan Rupee",
"Pataca", "Peso Uruguayo", "Philippine Peso", "Pound Sterling",
"Pula", "Qatari Rial", "Quetzal", "Rand", "Rial Omani", "Riel",
"Rufiyaa", "Rupiah", "Russian Ruble", "Rwanda Franc", "Saudi Riyal",
"Serbian Dinar", "Seychelles Rupee", "Singapore Dollar", "Som",
"Somoni", "Sri Lanka Rupee", "Sudanese Pound", "Surinam Dollar",
"Swedish Krona", "Swiss Franc", "Syrian Pound", "Taka", "Tanzanian Shilling",
"Tenge", "Trinidad and Tobago Dollar", "Tugrik", "Tunisian Dinar",
"UAE Dirham", "US Dollar", "Uganda Shilling", "Uzbekistan Sum",
"Won", "Yemeni Rial", "Yen", "Yuan Renminbi", "Zloty"), class = "factor"),
rgdpe = c(2574.41870117188, 2803.42724609375, 2943.32641601562,
3130.13989257812, 3535.80346679688), rgdpo = c(3043.74633789062,
3204.01831054688, 3399.08251953125, 3711.45483398438, 4192.33935546875
), pop = c(0.062149, 0.064622, 0.068235, 0.072504, 0.0767
), emp = c(NA, 0.0292000006884336, 0.030903272330761, 0.0329118072986603,
0.0348959788680077), avh = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), hc = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_)), row.names = c("ABW-1990", "ABW-1991",
"ABW-1992", "ABW-1993", "ABW-1994"), class = "data.frame")
One option to achieve your desired result would be to make use of purrr::pmap or mapply which both allow you to loop over multiple vectors or lists simultaneously.
Additionally, if you want to add title and/or caption you could do so via the title and caption arguments of labs()and set the style via theme options.
library(ggplot2)
library(tidyr)
library(dplyr)
library(purrr)
df1 %>%
select(year, rgdpe, rgdpo, avh, emp, hc) %>%
tidyr::gather(predictor, value, -year) %>%
ggplot() +
geom_line(aes(year, value)) +
facet_wrap(~predictor, scales = "free") +
labs(x = NULL, y = NULL, title = "Title of the Chart", caption = "Data source: World Bank") +
theme(plot.caption = element_text(face = 3, size = 9, hjust = 1)) +
purrr::pmap(
data.frame(
xint = c(1990, 1991),
lty = c(3, 1),
color = c("blue", "red")
),
function(xint, lty, color, lwd) geom_vline(xintercept = xint, color = color, linetype = lty, size = .5)
)
This question already has an answer here:
Conditional labeling in ggplot2 using geom_text and subsetting
(1 answer)
Closed 1 year ago.
I have a dot plot with data from dataframe df_roles$result and would like to assign labels only to certain dots specified by their specific name in df_roles$name.
My expected output is to have e.g. China labelled.
I have tried both these arguments but they won't work:
ifelse(df_roles$name = "China",
text(df_roles[[3]], df_roles[[2]], labels = df_roles[[1]], pos = 2, cex=0.3), " ")
geom_text(data = filter(df_roles$result, df_roles$name=="China"),aes(label=df_roles$name))
Reproducible example:
df_roles <- structure(list(name = structure(1:6, .Label = c("Afghanistan",
"Albania", "Algeria", "Angola", "Argentina", "Armenia", "Australia",
"Austria", "Azerbaijan", "Bahrain", "Bangladesh", "Barbados",
"Belarus", "Belgium", "Belize", "Benin", "Bolivia", "Bosnia and Herzegovina",
"Botswana", "Brazil", "Bulgaria", "Burkina Faso", "Burundi",
"Cameroon", "Canada", "Chile", "China", "Colombia", "Congo",
"Costa Rica", "Croatia", "Cuba", "Cyprus", "Democratic Republic of the Congo",
"Denmark", "Dominican Republic", "Ecuador", "Egypt", "El Salvador",
"Eritrea", "Estonia", "Ethiopia", "Finland", "France", "Gabon",
"Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada",
"Guatemala", "Guinea", "Guyana", "Haiti", "Honduras", "Hungary",
"India", "Indonesia", "Iran ", "Iraq", "Ireland", "Israel", "Italy",
"Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kuwait",
"Kyrgyzstan", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya",
"Lithuania", "Luxembourg", "Malawi", "Malaysia", "Mali", "Malta",
"Mauritania", "Mexico", "Mongolia", "Montenegro", "Morocco",
"Mozambique", "Namibia", "Nepal", "Netherlands", "New Zealand",
"Nicaragua", "Nigeria", "Norway", "Oman", "Pakistan", "Palestine",
"Panama", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
"Qatar", "Republic of Korea", "Republic of Moldova", "Romania",
"Russia", "Rwanda", "Saint Lucia", "Saint Vincent and the Grenadines",
"Saudi Arabia", "Senegal", "Serbia", "Singapore", "Slovakia",
"Slovenia", "Somalia", "South Africa", "Spain", "Sri Lanka",
"Sudan", "Suriname", "Sweden", "Switzerland", "Syria", "Taiwan",
"Tajikistan", "Thailand", "Togo", "Trinidad and Tobago", "Tunisia",
"Turkey", "Turkmenistan", "Uganda", "UK", "Ukraine", "United Arab Emirates",
"United Republic of Tanzania", "United States of America", "Uruguay",
"Uzbekistan", "Venezuela", "Viet Nam", "Yemen", "Zambia", "Zimbabwe"
), class = "factor"), result = c(0.0900102874778869, -0.0934265332577318,
-0.177974826946747, -0.590024694573266, 1.20884852383168, -0.183452483887309
)), row.names = c(NA, 6L), class = "data.frame")
Since the data shared does not have 'China' in it I am using 'Afghanistan' as an example. Also using row number as x-axis.
library(dplyr)
library(ggplot2)
df_roles %>%
mutate(name = as.character(name),
label = replace(name, name != 'Afghanistan', ''),
row = row_number()) %>%
ggplot(aes(row, result, label = label)) +
geom_point() + geom_text(vjust = -0.5)
I have a data frame where one of the column variable is the country. As an example see the vector with the countries.
country=c("Argentina", "Bahamas", "Barbados", "Belize", "Bolivia", "Brazil", "Virgin Islands", "Chile", "Colombia", "Costa Rica", "Cuba", "Dominica", "Dominican Republic", "Ecuador", "El Salvador", "French Guiana", "Guadeloupe", "Guatemala", "Guyana", "Haiti", "Honduras", "Jamaica", "Martinique", "Mexico", "Nicaragua", "Panama", "Paraguay", "Peru","St Lucia", "St Vincent", "Suriname", "Trinidad and Tobago", "Uruguay", "Venezuela", "Bangladesh", "Bhutan", "Brunei", "Cambodia", "India", "Indonesia", "Laos", "Malaysia", "Myanmar", "Nepal", "Pakistan", "Philippines", "Papua New Guinea", "Singapore", "SriLanka", "Thailand", "TimorLeste", "Vietnam", "Angola", "Benin", "Botswana", "BurkinaFaso", "Burundi", "Cameroon", "Central African Republic", "Chad", "Congo","Djibouti", "Democratic Republic of the Congo", "Equatorial Guinea", "Eritrea", "Ethiopia", "Gabon", "Gambia", "Ghana", "Guinea","Guinea Bissau", "Ivory Coast", "Kenya", "Lesotho", "Liberia", "Madagascar", "Malawi", "Mauritania", "Mali", "Mozambique", "Namibia","Niger", "Nigeria", "Rwanda", "Sudan", "Senegal", "Sierra Leone", "Somalia", "South Africa", "South Sudan", "Swaziland", "Tanzania", "Togo", "Uganda", "Zambia", "Zimbabwe", "Canada", "United States of America", "Albania", "Andorra", "Austria", "Belgium", "Bosnia", "Bulgaria", "Croatia", "Czech Republic", "Denmark", "Finland", "France", "Germany", "Greece", "Hungary", "Iceland", "Ireland", "Italy", "Liechtenstein","Luxembourg", "Macedonia", "Malta", "Montenegro", "Netherlands", "Norway", "Poland", "Portugal", "Romania", "Serbia", "Slovakia","Slovenia", "Spain", "Sweden", "Switzerland", "United Kingdom", "Afghanistan", "Algeria", "Bahrain", "Cyprus", "Egypt", "Iran","Iraq", "Israel", "Jordan", "Kuwait", "Lebanon", "Libya", "Morocco", "Oman", "Qatar", "Saudi Arabia", "Syria", "Tunisia", "Turkey","United Arab Emirates", "Western Sahara", "Yemen", "Armenia", "Azerbaijan", "Belarus", "Estonia", "Georgia", "Kazakhstan", "Kyrgyzstan", "Latvia", "Lithuania", "Moldova", "Russia", "Tajikistan", "Turkmenistan", "Ukraine", "Uzbekistan", "Japan", "Mongolia", "North Korea", "South Korea","China", "Australia", "Cook Islands", "Fiji", "French Polynesia", "Micronesia", "New Caledonia", "New Zealand", "Niue", "Samoa", "Solomon Islands", "Tonga", "Vanuatu")
I would like to separate these countries into tropical versus non-tropical (i.e. those within the tropical region and those that are outside. Does anyone have an idea of how can do this in R?
As #Sirius mentioned in the comments, there are lists like the following:
The csvData.csv can be downloaded here:
https://worldpopulationreview.com/country-rankings/tropical-countries
tropical_data <- read.csv("csvData.csv")
# tropical country (71)
country[country %in% tropical_data$country]
# non tropical country (115)
country[!country %in% tropical_data$country]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
This is the code that I have input:
CountriesChart = data.frame(NamesofC =
factor(c(Countries),
levels = c("Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic", "Chad", "China", "Colombia", "Comoros", "Congo", "Costa Rica", "Cote d'lvoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Federated States of Micronesia", "Fiji", "Finland", "France", "Gabon", "Georgia", "Germany", "Ghana", "Greece", "Greenland", "Grenada", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Lithuania", "Luxembourg", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Moldova", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Northern Mariana Islands", "North Korea", "Norway", "Oman", "Pakistan", "Palestine", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Phillipines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romana", "Russia", "Rwanda", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Solomon Islands", "Somalia", "South Africa", "South Korea", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", "The Gambia", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands, US.", "Yemen", "Zambia", "Zimbabwe")),
Values = c(OneData$exp_mean))
barplot(CountriesChart$Values, names = c(CountriesChart$levels))
I need to make this into a graph that shows the countries' names, but it won't show up because there are so many of them. What can I do to fix this? This is the end result of the graph with this code:
barplot(CountriesChart$Values, names = c(CountriesChart$levels), las=2)