Draw lines/plot without dataset - R

0 votes
Hi, i want to know can we draw graph or plots without dataframe but with dynamic values? How to free graphs without using dataframe?
Jul 23 in Data Analytics by raghav
18 views

1 answer to this question.

0 votes

Hi @raghav,

You can draw specific graphs only such as line or segment, bar, etc.

You can draw these using annotate function from the ggplot package.

Let me give you some R codes for such plots

library(ggplot2)

# Rect or bar chart -------------------------------------------------------

ggplot() + lims(x = c(0,10), y = c(1,10)) + annotate("rect",xmin = 5,xmax = 6, ymax = 7,ymin = 3) + 
  annotate("rect",xmin = 3,xmax = 4, ymax = 7,ymin = 1) + annotate("rect",xmin = 7,xmax = 8, ymax = 7,ymin = 5)

# Line or segment ---------------------------------------------------------

ggplot() + lims(x = c(0,10), y = c(1,10))+ annotate("segment",x = 3,xend = 6, yend = 7,y = 3) + 
  annotate("segment",x = 4,xend = 8, yend = 8,y = 2) + annotate("segment",x = 3.6,xend = 6.1, yend = 4,y = 1) 

# PointRange --------------------------------------------------------------

ggplot() + lims(x = c(0,10), y = c(1,10)) + annotate("pointrange", ymax = 7,ymin = 3,x = 3,y = 5) +
  annotate("pointrange", ymax = 8,ymin = 3,x = 5,y = 6) + annotate("pointrange", ymax = 5,ymin = 1,x = 7,y = 3)

Images for above plots

  

answered Jul 24 by anonymous

Related Questions In Data Analytics

0 votes
1 answer

Save a plot as image on the disk using R

Consider for both the situations: 1. Image will ...READ MORE

answered Apr 13, 2018 in Data Analytics by darklord
• 6,140 points
87 views
0 votes
2 answers

How to write lines to a text file in R?

sink("outfile.txt") cat("hello") cat("\n" ...READ MORE

answered May 24 in Data Analytics by anonymous
1,411 views
0 votes
1 answer

How to plot side-by-side Plots with ggplot2 in R?

By Using gridExtra library we can easily ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,700 points
1,280 views
0 votes
1 answer

Unload a package without restarting R

Try the below option: detach("package:vegan", unload=TRUE) NOTE: You can ...READ MORE

answered Apr 17, 2018 in Data Analytics by DataKing99
• 8,100 points
124 views
0 votes
1 answer

Plot two variables as lines on the same graph using ggplot

If you have small number of variables, ...READ MORE

answered Apr 17, 2018 in Data Analytics by kappa3010
• 2,020 points
883 views
0 votes
1 answer

How to print new lines with print() in R?

You can use cat() instead of writeLines(): ...READ MORE

answered May 3, 2018 in Data Analytics by kappa3010
• 2,020 points
21 views
0 votes
0 answers

How to edit the labels and limit if a plot using ggplot? - R

How to edit the labels and limit ...READ MORE

Jul 15 in Data Analytics by piyush
9 views
0 votes
0 answers

How to provide color to ggplot scatter chart depending on field value?

How to provide color to ggplot scatter ...READ MORE

Jul 16 in Data Analytics by anonymous
12 views
0 votes
0 answers

which to use fill or color to show colors in R plots?

which to use fill or color to ...READ MORE

Jul 22 in Data Analytics by deepa
12 views
0 votes
0 answers

plot a line chart along with point labels in the plot

Can someone help me to plot a ...READ MORE

Jul 22 in Data Analytics by lokesh
10 views