ggplot2 : polygon edge not found

I meet the problem everytime I use ggplot2, which means everyday. Reaaaaaaly need help!

my code resource is here:

install.packages("dplyr")
install.packages("ggplot2")
library(dplyr)
library(ggplot2)
summary(supersonic)
supersonic %>%
group_by(channel) %>%
summarise(gross_profit = sum(profit)) %>%
ggplot(aes(x=gross_profit, y=reorder(channel, gross_profit))) +
geom_bar(stat = "identity") +
geom_text(aes(label = scales::dollar(gross_profit, accuracy = 1)),
hjust = 1, color = "white", fontface = "bold") +
theme_ipsum_ps() +
labs(x="Gross Profit", y="Channel", title = "Profit per channel")

and the console report below:
Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
polygon edge not found
In addition: Warning message:
In grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
no font could be found for family "IBMPlexSans"

Hi!

To help us help you, could you please turn this into a proper reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

> head (supersonic)
  id business   channel region age_demo gender hhi   profit
1  1       NA   Twitter      1        4   Male  NA 343.0659
2  2        0   Twitter      3        3 Female  NA 318.1855
3  3        1   Twitter      4        3 Female  NA 316.6524
4  4        1 Instagram      2        3 Female  NA 276.4889
5  5       NA   Twitter      2        3   Male  NA 371.0668
6  6       NA Instagram      1        2 Female   3 249.1170

Hi @Katherine23 , and welcome!

Judging from the error messages, it looks like there's a step to install the necessary fonts to use theme_ipsum_ps. See import_plex_sans() from the theme_ipsum_ps help page
(?hrbrthemes::theme_ipsum_ps ).

The fonts from hbrthemes after running the function import_plex_sans() are located in [~/Library/R/4.1/library/hrbrthemes/fonts/plex-sans], or similar depending on your computer OS. You will also probably have to copy the font to your system or user level font directory.

library("dplyr")
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library("ggplot2")
library("hrbrthemes")
#> NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
#>       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
#>       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow


options(hrbrthemes.loadfonts = TRUE)

supersonic <- structure(list(id = 1:6, business = c(NA, 0L, 1L, 1L, NA, NA), 
    channel = c("Twitter", "Twitter", "Twitter", "Instagram", 
    "Twitter", "Instagram"), region = c(1L, 3L, 4L, 2L, 2L, 1L
    ), age_demo = c(4L, 3L, 3L, 3L, 3L, 2L), gender = c("Male", 
    "Female", "Female", "Female", "Male", "Female"), hhi = c(NA, 
    NA, NA, NA, NA, 3L), profit = c(343.0659, 318.1855, 316.6524, 
    276.4889, 371.0668, 249.117)), class = "data.frame", row.names = c(NA, 
-6L))

supersonic %>%
group_by(channel) %>%
summarise(gross_profit = sum(profit)) %>%
ggplot(aes(x=gross_profit, y = reorder(channel, gross_profit))) +
geom_bar(stat = "identity") +
geom_text(aes(label = scales::dollar(gross_profit, accuracy = 1)),
hjust = 1, color = "white", fontface = "bold") +
theme_ipsum_ps() +
labs(x="Gross Profit", y="Channel", title = "Profit per channel")

Created on 2021-09-29 by the reprex package (v2.0.1)

Thank you for your reply!
I tried to reinstall the font like you said. Luckily, there is no error about the IBMPlexSans”.
However there is still a grid.Call problem. Do you know what does it mean?

Error in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
  polygon edge not found

From the error message, it says it's having trouble placing a text element relative to the plot area.

Does it work if you copy the code as I've posted or if you leave out theme_ipsum_ps() ?

1 Like

It worked! Thank you soooo much!
I am a new learner with R and I am trying to understand the code meaning.
Many thanks again!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.