Comments (7)
The only further thought I have is "oops, I forgot to upload this" :)
I don't have time right now to make this a nice function, but for those who are searching, here's my plotting code. Hopefully, I'll soon have time and remember to turn this into a function within the conStruct package, but in the mean time, here goes:
#' # Construct-related plots for the paper
library(tidyverse)
library(ggspatial)
library(ggplot2)
library(sf)
library(rnaturalearth)
library(rnaturalearthdata)
library(ggforce)
library(foreach)
theme_set(theme_bw())
#' # Fancy piemaps
#'
#' This looted from https://stackoverflow.com/questions/51398344/r-pie-charts-distorted-when-adding-to-projected-map-using-ggplot
world = map_data("world", resolution=0)
basem = ggplot(data=world, aes(x=long, y=lat, group=group)) +
geom_polygon(color = "grey", fill="white") +
coord_quickmap(xlim = c(-12, 55), ylim = c(34, 60)) +
ylab("Latitude") +
xlab("Longitude") +
theme(
panel.background = element_rect(fill = "lightsteelblue2"),
panel.grid = element_blank(),
legend.position = "top")
basem
pie.list = csvmap_data %>%
tidyr::nest(c(pop, proportion)) %>%
# make a pie chart from each row, & convert to grob
mutate(pie.grob = purrr::map(data,
function(d) ggplotGrob(ggplot(d, aes(x = 1, y = proportion, fill = pop)) +
geom_col(show.legend = FALSE) +
scale_fill_manual(values=gautam.pal.k3) +
coord_polar(theta = "y") +
theme_void()))) %>%
# convert each grob to an annotation_custom layer.
rowwise() %>%
mutate(radius = 0.9) %>%
mutate(subgrob = list(annotation_custom(grob = pie.grob,
xmin = longitude - radius, xmax = longitude + radius,
ymin = latitude - radius, ymax = latitude + radius)))
basem +
pie.list %>%
filter(mdl=="sp", K==3) %>%
pull(subgrob)
basem +
pie.list %>%
filter(mdl=="sp", K==2) %>%
pull(subgrob)
from construct.
Hi, @kdm9 - glad it's being helpful! And gee - it looks to me like the distortion in the first map is coming from being squished horizontally, not from the map projection - here's a zoom in on a northern and a southern pie plot in exactly the same rectangle:
This can happen if you plot to a window in R and then save it out as a pdf to a different aspect ratio image - how are you saving it to a file?
from construct.
Hi Peter,
Thanks for your help! Yes, it's odd isn't it.
I'm using ggsave, with an a4-compatible width and height (6" by 7"). It is a bit suspicious, but I don't think the save aspect ratio is the direct cause. See for example below, which is what happens when you use an export size of 6" by 20" wide. The plot isn't stretched, it seems to keep its own native aspect ratio (nb the large white margins on each side). Additionally, if one scales points to the equator to the poles and then plot, one can see a trend of squishedness from the equator to the poles.
from construct.
Ah, ok, you're right. How about this?
https://stackoverflow.com/questions/51398344/r-pie-charts-distorted-when-adding-to-projected-map-using-ggplot
from construct.
Ah, fantastic! Many thanks. I googled extensively, but looks like I missed that SO question/answer. I'd be happy to write a small section for the construct vignette with example code once it's working if that's of interest, since this is something others probably could use too.
from construct.
That'd be great Kevin - thanks!
from construct.
Hey Kevin - I'm going to close this issue, but feel free to reopen if you have further thoughts/problems with this!
from construct.
Related Issues (20)
- Error freqs using RADseq data HOT 7
- (Non-Issue) Question about parallelization in cross-validation analysis... HOT 2
- Extracting all iterations from model.fit object HOT 6
- element that is not positive definite, xvalidation HOT 3
- Installing covariance_fix issue HOT 8
- Resuming an unfinished CV run? HOT 12
- Chain Does Not Update from Iteration 1 HOT 4
- Predictive accuracy increasing over all values of K from X-Val HOT 4
- error creating the vignettes in conStruct HOT 2
- Make thin value adjustable? HOT 4
- Most differentiated samples grouped in the same layer HOT 4
- Messy data with lots of errors.. HOT 3
- structure2conStruct error HOT 4
- View admixture proportions with associated sample names HOT 5
- Questions about results interpretation HOT 7
- AF sometimes 1 HOT 3
- High Rhat and ESS issues for K>1 with spatial analyses HOT 4
- Is parallelization possible? HOT 2
- Cross-validation error: check.data.partitions.arg() HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from construct.