Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting shape with geom_mark_rect #304

Closed
meghanmshea opened this issue Jul 6, 2023 · 1 comment
Closed

Adjusting shape with geom_mark_rect #304

meghanmshea opened this issue Jul 6, 2023 · 1 comment

Comments

@meghanmshea
Copy link

meghanmshea commented Jul 6, 2023

I've been trying to make a reproducible version of a diagram of the sampling scheme for a particular field project, mirroring this version that I made by hand in PowerPoint:

PowerPoint Figure Version

Geom_mark_rect has been super helpful for creating boxes around the collections of points. However, I've been having trouble making the boxes fit more tightly around the points (and not being forced to squares); when I try to make a similarly narrow version of the R figure, the boxes overlap:

R Figure Version

It would be great if there were a way to make the geom_mark_rect boxes tighter around the points; any advice on parameters to change or things to try would be greatly appreciated. The code used to produce the R figure is below, where data_forchart can be imported from the attached .csv:

facet.labs =  c("Tide Pool 1\n (S1)", "Tide Pool 2\n (S2)", "Nearshore\n (N)")
names(facet.labs) = c("S1", "S2", "N")

data_forchart$Location= factor(data_forchart$Location, levels=c("S1", "S2", "N"))
data_forchart$chart_num= factor(data_forchart$chart_num, levels=c("3", "2", "1"))


sample_schema = ggplot(data = data_forchart, aes(x = Time, y = chart_num, shape = Location, color = Time, fill = Time)) + 
  geom_beeswarm(cex= 2, size = 3) + 
  geom_mark_rect(expand = .03) +
  scale_shape_manual(values = c(15, 17, 16)) + 
  viridis::scale_color_viridis(discrete=TRUE, begin = 0, end = .97, direction = -1) +
  viridis::scale_fill_viridis(discrete=TRUE, begin = 0, end = .97, direction = -1) +
  facet_grid(Location ~., scales = "free_y", space = "free_y", switch = "y", labeller = labeller(Location = facet.labs)) +
  theme_void(base_size = 16) + 
  theme(legend.position = "none") +
theme(strip.text.y.left = element_text(angle = 0, hjust = 1, vjust = .9)) 

Chart_Data.csv
28-Jan-2022-TideChart.txt

@thomasp85
Copy link
Owner

I'm afraid this is a case of the tool being used for the wrong job. Since the mark geoms always calculate expansion in the render dimension it will be eternally fiddly to try to make it match your vision.

You'd be better off calculating the right dimensions that fits the coordinates of your data and then using geom_shape() to round the corners

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants