ggplot2 - ggplot - Basic example of ggplot2 - ggplot2 tutorial - ggplot tutorial



  • First with defaults and the with some customization of the parameters.
#help("mtcars")
fit <- lm(mpg ~ wt, data = mtcars)
bs <- round(coef(fit), 3) 
lmlab <- paste0("mpg = ", bs[1],
                ifelse(sign(bs[2])==1, " + ", " - "), abs(bs[2]), " wt ")
#range(mtcars$wt)
library("ggplot2")

#with defaults
ggplot(aes(x=wt, y=mpg), data = mtcars) +  
  geom_point() +
  geom_smooth(method = "lm", se=FALSE, formula = y ~ x)
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ggplot2 tutorial - ggplot tutorial - ggplot2 - ggplot - learn ggplot2 - ggplot2 examples - team

Learn ggplot2 - ggplot2 tutorial - Plot for Fyc0l - ggplot2 examples - ggplot2 programs

#some customizations
ggplot(aes(x=wt, y=mpg,colour="mpg"), data = mtcars) +  
geom_point(shape=21,size=4,fill = "blue",alpha=0.55, color="red") +
scale_x_continuous(breaks=seq(0,6, by=.5)) +
geom_smooth(method = "lm", se=FALSE, color="darkgreen", formula = y ~ x) +
geom_hline(yintercept=mean(mtcars$mpg), size=0.4, color="magenta") +
xlab("Weight (1000 lbs)") + ylab("Miles/(US) gallon") +
labs(title='Linear Regression Example',
     subtitle=lmlab,
     caption="Source: mtcars") +
annotate("text", x = 4.5, y = 21, label = "Mean of mpg") +
annotate("text", x = 4.8, y = 12, label = "Linear adjustment",color = "red") +
theme_bw() 
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ggplot2 tutorial - ggplot tutorial - ggplot2 - ggplot - learn ggplot2 - ggplot2 examples - team

Learn ggplot2 - ggplot2 tutorial - Linear Registration - ggplot2 examples - ggplot2 programs


This ggplot tutorial provides you the following points such as ggplot2 , ggplot , ggplot r , r ggplot2 , ggplot2 examples , ggplot title , ggplot legend , ggplot examples , ggplot legend title , ggplot colors , ggplot2 legend , ggplot aes , ggplot axis labels , ggplot2 colors , remove legend ggplot2 , ggplot2 histogram , ggplot histogram , ggplot2 tutorial , ggplot cheat sheet , ggplot boxplot , ggplot barplot , ggplot2 cheat sheet , ggplot2 boxplot , ggplot theme , ggplot tutorial , ggplot scatter plot , ggplot facet , ggplot2 theme , ggplot pie chart , ggplot stacked bar , pie chart ggplot2 , ggplot2 book , r cookbook ggplot2 , ggplot2 gallery , pie chart in r ggplot2 , r ggplot2 tutorial , ggplot book

Related Searches to