Showing posts with label Data Frame. Show all posts
Showing posts with label Data Frame. Show all posts

Sunday, December 17, 2017

How do you draw a bar graph from a table of X,Y values?

In a previous post you saw how to create a data frame in R using a set off x and y values as shown:

  x      ItmVal
1 A     69
2 B     47
3 C     11
4 D     12
5 E     42
6 F     24


Here 1 to six are line numbers.

It is easy to draw a bar graph using this data:
------
>  dap <- br="" data.frame="">+  x=factor(c("A","B","C","D","E","F"), levels=c("A","B","C","D","E","F")),
+ ItmVal=c(69,47,11,12,42,24)
+ )
-----------
You map the data to aesthetics as shown and you can display your graph as shown.


ggplot-bargraph1

On the other hand if you want a different color for each of the different x values you could use this:


ggplot_bargraph2

Friday, December 15, 2017

How do I ‌put x and y values as data input in R programming?

In constructing relationship between x and y, we create a table with two columns, with x in the first column and corresponding y in the second column. The value of x may be discrete (numeric or non-numeric) or continuous(numeric) and y is numeric. A graph with x and y represents the table of values.
In the following there are six categories (A through F) and for each of these categories a value has been assigned (67,47,11,12,22,24). Now how do I create a data in R that I could work on?
This is easily carried out by creating a data frame as shown:

> dap <- br="" data.frame="">+  x=factor(c("A","B","C","D","E","F"), levels=c("A","B","C","D","E","F")),
+ ItmVal=c(69,47,11,12,42,24)
-----------------------------------


DataFrameDiscrete.png