Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lower trailing parts of letters "g" and "y" etc hidden/cut off/overwritten in ggplot labels

The bottom parts of the "y"'s and "g"'s are cut off in this map. See "dryland" and "irrigated" under soy.

enter image description here

What setting controls this? Here is my theme_map function

theme_map <- function (base_size = 12, base_family = "") {
  theme_gray(base_size = base_size, base_family = base_family) %+replace% 
    theme(
      axis.line=element_blank(),
      axis.text.x=element_blank(),
      axis.text.y=element_blank(),
      axis.ticks=element_blank(),
      axis.ticks.length=unit(0.3, "lines"),
      axis.ticks.margin=unit(0.5, "lines"),
      axis.title.x=element_blank(),
      axis.title.y=element_blank(),
      legend.background=element_rect(fill="white", colour=NA),
      legend.key=element_rect(colour="white"),
      legend.key.size=unit(1.2, "lines"),
      legend.position="right",
      legend.text=element_text(size=rel(0.8)),
      legend.title=element_text(size=rel(0.8), face="bold", hjust=0),
      panel.background=element_blank(),
      panel.border=element_blank(),
      panel.grid.major=element_blank(),
      panel.grid.minor=element_blank(),
      panel.spacing=unit(0, "lines"),
      plot.background=element_blank(),
      plot.margin=unit(c(1, 1, 0.5, 0.5), "lines"),
      plot.title=element_text(size=rel(1.2)),
      strip.background=element_rect(fill="white", colour="white"),
      strip.text.x=element_text(size=rel(.8)),
      strip.text.y=element_text(size=rel(0.8), angle=-90) 
    )   
}

I am just dipping my toe into ggplot2 after spending a long time as a curmudgeonly devotee of base graphics. I found that theme_map function on the internet somewhere, so I don't understand it yet. Can someone please tell me which of those settings I'd need to tweak to solve my problem?

Here's my code for generating (one of) those maps, but I'm assuming that the relevant part is in the theme_map function

mapcorn <- ggplot(USA_fort_premade) + 
    aes(long,lat,group=group) + 
    geom_polygon(aes(x=long,y=lat, group=group, fill=yield.mean), 
                 data=REAP_fort_corn)+
    geom_path(color="grey", lwd = .1) +
    coord_fixed(1.3) +
    facet_wrap( ~ irr) +
    scale_fill_gradient2(low = rgb(.9, .4, 0), mid = rgb(.9, .9, 0),
                         high = rgb(0,.8,0), midpoint = mean(REAP_fort_corn$yield.mean, na.rm = TRUE), 
                         space = "Lab", name = "bu/ac",
                         na.value = "grey50", guide = "colourbar") +
    theme_map() +ggtitle("Corn")

Apologies for not reproducible, but the data is huge and this should be a fairly simple question. A hard one to google however if you don't know the terms.

like image 697
generic_user Avatar asked Nov 16 '17 22:11

generic_user


1 Answers

If those are the facet strip labels, try strip.text.x=element_text(margin=margin(b=5)), where b is the bottom margin in points. Set it to whatever value is large enough to get the complete text to appear. You can adjust the top, right, bottom, and left margins with margin=margin(t=5, r=2, b=7, l=2), or whatever values work for your plot.

like image 97
eipi10 Avatar answered Oct 15 '22 20:10

eipi10