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, 2019 in Data Analytics by raghav
264 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, 2019 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 Sahiti
• 6,360 points
781 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, 2019 in Data Analytics by anonymous
14,230 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

edited Jun 9, 2020 by MD 5,641 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,240 points
1,470 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,090 points
2,734 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,090 points
128 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, 2019 in Data Analytics by anonymous
• 32,910 points
113 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, 2019 in Data Analytics by anonymous
• 32,910 points
117 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, 2019 in Data Analytics by komal
91 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, 2019 in Data Analytics by anonymous
• 32,910 points
306 views