Error message: object of type 'closure' is not subsettable

Hi, there is something wrong with my code, I keep have error message "Error: object of type 'closure' is not subsettable", any suggestions?

library(ggplot2)
library(ggpubr)
library(extrafont)
# Register fonts with R
library(extrafontdb)
######
#Basic Dirac plot

plot_d <- ggplot() +
  #geom_line(aes(l0, 0), size = 1) +
  geom_segment(aes(x=5, xend=5, y=0, yend=1.5), size=1.5,
               arrow = arrow(length = unit(0.2, "cm"), type = "closed")) +
  geom_segment(aes(x=0, xend=0, y=0, yend=1.5),
               arrow = arrow(length = unit(0.2, "cm"), type = "closed")) +
  geom_segment(aes(y=0, yend=0, x=0, xend=10),
               arrow = arrow(length = unit(0.2, "cm"), type = "closed")) +
  geom_text(size = 5, aes(10, -0.1, label = "x"), family=font) +
  geom_text(size = 5, aes(5, -0.1, label = "x[0]"),parse = T,  family=font) +
  geom_text(size = 5, aes(-0.5, 1.5, label = "f(x)"), family=font) +
  geom_text(size = 5, aes(6.5, 1.45, label = "delta(x-x[0])"), parse = T, family=font) +
  geom_text(size = 5, aes(0, -0.1, label = "0"), family=font) +
  theme_void()
plot_d

Thanks

I can't reproduce your issue, Can you check your reprex and make sure it reproduces the problem?

library(ggplot2)

# Using some random font since you haven't specified the value of the `font` variable
font = "Cloud Calligraphy"

ggplot() +
    geom_segment(aes(x=5, xend=5, y=0, yend=1.5), size=1.5,
                 arrow = arrow(length = unit(0.2, "cm"), type = "closed")) +
    geom_segment(aes(x=0, xend=0, y=0, yend=1.5),
                 arrow = arrow(length = unit(0.2, "cm"), type = "closed")) +
    geom_segment(aes(y=0, yend=0, x=0, xend=10),
                 arrow = arrow(length = unit(0.2, "cm"), type = "closed")) +
    geom_text(size = 5, aes(10, -0.1, label = "x"), family = font) +
    geom_text(size = 5, aes(5, -0.1, label = "x[0]"),parse = T,  family = font) +
    geom_text(size = 5, aes(-0.5, 1.5, label = "f(x)"), family=font) +
    geom_text(size = 5, aes(6.5, 1.45, label = "delta(x-x[0])"), parse = T, family = font) +
    geom_text(size = 5, aes(0, -0.1, label = "0"), family = font) +
    theme_void()

Created on 2021-03-30 by the reprex package (v1.0.0.9002)

Thank you, it works when I delete all "family = font" code, seems something wrong with the packages.

You often see this whenever some function receives as an argument an object that is the name of a builtin function. That's why I avoid names like df, data, etc.

1 Like

This topic was automatically closed 21 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.