- Related Questions & Answers
- How to join points in a point chart with lines using ggplot2 in R?
- How to create a point chart with empty points using ggplot2 in R?
- How to create a point chart for categorical variable in R?
- How to represent all values of X-axis or Y-axis on the graph in R using ggplot2 package?
- How to change the color of X-axis label using ggplot2 in R?
- How to create a point chart for cumulative sums using ggplot2 in R?
- How to X-axis labels to the top of the plot using ggplot2 in R?
- C Program to check if the points are parallel to X axis or Y axis
- How to align the bars of a barplot with the X-axis using ggplot2 in R?
- How to change the gridlines of Y-axis on a chart created by using ggplot2 in R?
- How to write partial title of X-axis in italics using ggplot2 of R?
- How to change the automatic sorting of X-axis of a bar plot using ggplot2 in R?
- How to reverse the X-axis labels of scatterplot created by using ggplot2 in R?
- How to increase the size of points on a scatterplot if the points are drawn based on another sequence using ggplot2 in R?
- How to display long X-axis labels in a bar chart using plotly in R?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

A point chart is usually drawn to see the relationship between two continuous variables and it is also called scatterplot but if the independent variable is categorical then we simply call it a point chart. Often, we want to join or connect the points of a point chart to visually represent the variation of categories of the independent variable and make it a line chart. This can be done by setting stat_summary argument geom to line and setting group = 1 in aes.

Consider the below data frame −

Class<-c("A","B","C") Frequency<-c(23,24,12) df<-data.frame(Class,Frequency) df

Class Frequency 1 A 23 2 B 24 3 C 12 library(ggplot2)

Creating a simple point chart −

ggplot(df,aes(x,y,group=1))+geom_point()

Creating the plot with connected points −

ggplot(df,aes(x,y,group=1))+geom_point()+stat_summary(fun.y=sum,geom="line")

Advertisements