Nick
Nick

Reputation: 11

geom_smooth does not plot line of best fit

I hope this question isn't a duplicate. I tried to find answers per the site's requirements before posting, but since I am so new, the help forums are too foreign to me.

Following Wickham's R for data visualization, I easily used geom_point for an integrated data set, mpg:

smooth fit for integrated data set

simple reference code:

ggplot(data = mpg)+
    geom_smooth(mapping = aes(x=displ, y=hwy))+
    geom_point(mapping = aes(x=displ, y=hwy))

Excited by this cool plot, I tried to do the same for some personal research data, which describes inteferon-beta production over five time points (A,b,c,d,e instead of numerical data).

I used the same code, essentially:

ggplot(data = ifnonly)+
    geom_smooth(mapping = aes(x=HOURS, y=IFNB))+
    geom_point(mapping = aes(x=HOURS, y=IFNB))

IFNb expression at five timepoints

Unfortunately, the line does not display. In fact, nothing displays until I add the geom_point function. What am I missing here? Is there more complex code required or is there some subtlety that I can apply to future uses of this function and ggplot?

Upvotes: 1

Views: 1875

Answers (1)

SNEHA
SNEHA

Reputation: 77

I think you should get your desired output with following one line code

          library(ggplot2)
          ggplot(mtcars, aes(disp,mpg))+geom_smooth() # one line code where I have mentioned data is mtcars , and disp as x axis and mpg as y axis you could get following output  
    # please check this link for output 

o/p without geom_point

         library(ggplot2)
          ggplot(mtcars, aes(disp,mpg))+geom_smooth()+geom_point()

o/p with geom_point

Upvotes: 0

Related Questions