Using ggplot, my graph displays the axis, but it is a blank graph with no lines on it. Why is that so?

I am trying to plot the k_concentration ratios and this is my plotting code: dat_kcon <- dat_kcon %>%
kc_vars(sa_total_income, fisc_yr, nic_sect_name_short)

ii. K-C at nic-year level

kcon_nic_yr <- dat_kcon %>%
agg_nic_yr(nic = nic_sect_name_short, year = fisc_yr, share = share,
wt1 = sa_total_income, wt2 = sa_total_assets)

vii. K-C by year

kcon_yr <- kcon_nic_yr %>% agg_year(year = fisc_yr, k = k_concentration, nobs = nobs, wt1 = wt1,
wt2 = wt2)

viii. plot aggregate K-C by year

p <- plot_conc_k(dat1 = kcon_yr, xvar = fisc_yr, yvar = "K-C", zvar = "Weightage",
dat2 = kcon_top, wt1 = wt1, wt2 = wt2)
p <- ggplot(kcon_yr, aes(x = fisc_yr, y = 'K-C', col = Weightage)) +
geom_line(lwd = 1.25) +
scale_y_discrete(limits = c(0, 1)) +
labs(x = "Financial Year", y = "K-C") +
scale_color_manual(labels = c("Observations", "No weight", "Total Income",
"Total Assets"),
values = c("red", "dark green", "light blue", "purple"))

xi. save plot

ggsave("kcon_inc_yr.jpg", plot = p, width = 8, height = 4)

x. save K-C's by year in csv format

kcon_yr %>%
pivot_wider(names_from = "Weightage", values_from = "K-C") %>%
write_csv('kcon_inc_yr.csv', append = F)

are there any errors?

It's hard to know without knowing what the data looks like. It would help if you could share a reprex.

One possibility though: are you sure K-C should be in quotes? Were you trying to use a backquote ` ? Try replacing with:

p <- ggplot(kcon_yr, aes(x = fisc_yr, y = `K-C`, col = Weightage)) +

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.