Luís de Sousa
Luís de Sousa

Reputation: 6842

ggplot2 - change line width in function graph

Say I have function like:

quad <- function(x)
{
    return (x^2)
}

That I plot using ggplot:

plot <- ggplot(data.frame(x=c(0,4)), aes(x = x)) +
        stat_function(fun = quad)

So far, so good, but the line is really thin. I thus add some specific geometry to the line:

plot + geom_line(size=2)

But it returns this error:

Error: geom_line requires the following missing aesthetics: y

How can I manipulate line geometry in this type of graphs?

Upvotes: 1

Views: 2916

Answers (1)

Lu&#237;s de Sousa
Lu&#237;s de Sousa

Reputation: 6842

After playing around a while I found out that an argument named size can be passed into stat_function. It has the same effect as gem_line:

plot <- ggplot(data.frame(x=c(0,4)), aes(x = x)) +
        stat_function(fun = quad, size=1.5)

Upvotes: 2

Related Questions