user1471980
user1471980

Reputation: 10656

removing black border from ggplot

My df:

Time       CPU
1:00:00    10
1:10:00    40
1:24:03    50

etc.

I am building a ggplot with this:

p <- ggplot(df, aes(Time, CPU)) + geom_line()

When I add the below code to the existing ggplot code, it puts a black border on the graph. Is there any way to remove that black border line around the plot?

p + opts(plot.background=theme_rec(fill="lightblue"),panel.background=theme_rect(fill='#D6E7EF')) + ylim(0,100) + opts(panel.grid.major = theme_line(size = 0.7, colour = 'white'), panel.grid.minor = theme_blank(), axis.ticks=theme_blank())

Upvotes: 3

Views: 4511

Answers (1)

Dennis
Dennis

Reputation: 762

You should do the following:

  1. Update your R to the current 2.15.2 version.
  2. Install the new versions of ggplot2, plyr, scales and gtable in a fresh R session with no other packages loaded apart from the standard autoloads.

This should more or less replicate what was in 0.9.0 using the new system. The plot I ended up with did not have a black border, so see if this works for you:

p <- ggplot(DF, aes(x, y)) + geom_line()
p + theme(plot.background = element_rect(fill="lightblue"),
         panel.background = element_rect(fill='#D6E7EF'),
         panel.grid.major = element_line(size = 0.7, colour = 'white'), 
         panel.grid.minor = element_blank(), 
         axis.ticks = element_blank()) +
    ylim(0, 5)

The primary changes are that opts() is now theme(), and theme_* is now element_*. In addition, a few new theme elements were added in order to support an inheritance structure of elements in the new system. For example, consider axis.text.y; this theme element inherits from axis.text, which in turn inherits from axis. There are a number of other changes, too, but unless you're writing theme functions, these are the primary ones that will arise in practice.

Upvotes: 4

Related Questions