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
46 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,190 points
162 views
0 votes
3 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
2,814 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,720 points
1,870 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,130 points
268 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,070 points
1,160 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,070 points
32 views
0 votes
1 answer

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

Add a limit to axis ticks using ...READ MORE

answered Nov 3 in Data Analytics by anonymous
• 32,260 points
24 views
0 votes
1 answer

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

cyl is a continuous value field, so ...READ MORE

answered Nov 2 in Data Analytics by anonymous
• 32,260 points
25 views
0 votes
1 answer

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

The color attribute is only used for ...READ MORE

answered Nov 4 in Data Analytics by komal
26 views
0 votes
1 answer

plot a line chart along with point labels in the plot

Follow the below steps: 1. Create a ggplot ...READ MORE

answered Nov 2 in Data Analytics by anonymous
• 32,260 points
28 views