Konrad
Konrad

Reputation: 18595

Controlling ticks and odd text in a pie chart generated from a factor variable in ggplot2

I'm generating a simple pie chart with use of the code below:

data(mtcars)
mtcars$fac_var <- as.factor(mtcars$cyl)
require(ggplot2); require(ggthemes)

# Chart
pie_test <- ggplot(mtcars, aes(x = factor(1), fill = fac_var)) +
  geom_bar(width = 1) +
  coord_polar(theta = "y") +
  ggtitle("Title") +
  theme_pander() +
  scale_fill_tableau(name = "Something") +
  theme(axis.title = element_blank())

The code produces the following chart:

first pie chart

I'm interested in introducing two minor modifications to the chart above:

  1. I would like to remove the figure 1 visible on the left (highlighted in red in the picture below).
  2. I would like to make the lines leading to to the figures more strongly pronounced (highlighted in black in the picture below).

Desired changes:

Desired changes pie chart

Upvotes: 1

Views: 372

Answers (1)

SamanthaDS
SamanthaDS

Reputation: 1143

1.) To get rid of the "1-" edit your theme to:

theme(axis.title = element_blank(),
      axis.ticks.y = element_blank(),
      axis.text.y = element_blank())

2.) To change the lines edit your theme to:

theme(axis.title = element_blank(), 
      axis.ticks.y = element_blank(),
      axis.text.y=element_blank(),
      panel.grid.major.y = element_line(size = 1, color="black", linetype = "solid"))

Not a perfect solution but an improvement. Pie charts are not the best for conveying data. You may want to consider a bar chart. If you want more help with ggplot2 pie charts check out this post.

Upvotes: 1

Related Questions