-1

I have the following data.frame:

data <- structure(list(ItemID = c(214507224L, 214507239L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L, 214507331L), SessionID = c(4765238L, 1151253L, 3412203L, 765141L, 960657L, 5643776L, 3310138L, 1246822L, 11254413L, 436751L, 9551463L, 2347782L, 813858L, 7649777L, 6594807L, 3214991L, 4879403L, 3306326L, 11023918L, 5332954L), Avg = c(0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0), diffinscnd = c(0, 0, 0, 0, 0, 2602.11800003052, 0.132999897003174, 0, 2157.50600004196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), total_clicks = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), unique_Category = c(1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), unique_items = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), ICR = c(0, 0, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927, 0.47992700729927), Category = structure(c(1L, 1L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L, 34L), .Label = c("0", "1", "10", "11", "12", "2", "2088433845", "2088919107", "2088942073", "2088966627", "2088995234", "2089040513", "2089046251", "2089046255", "2089046367", "2089074648", "2089156185", "2089221555", "2089282248", "2089282437", "2089314317", "2089318476", "2089437536", "2089440540", "2089440550", "2089531793", "2089538467", "2089574086", "2089615479", "3", "4", "5", "5862467", "6", "7", "8", "9", "S"), class = "factor")), row.names = c(NA, 20L), class = "data.frame")

> str(data)
'data.frame':   2127387 obs. of  9 variables:
 $ ItemID         : int  214507224 214507239 214507331 214507331 214507331 214507331 214507331 214507331 214507331 214507331 ...
 $ SessionID      : int  4765238 1151253 3412203 765141 960657 5643776 3310138 1246822 11254413 436751 ...
 $ Avg            : num  0 0 1 0 0 0 1 1 1 1 ...
 $ diffinscnd     : num  0 0 0 0 0 ...
 $ total_clicks   : int  1 1 1 1 1 2 2 1 2 1 ...
 $ unique_Category: int  1 1 1 1 1 2 1 1 2 1 ...
 $ unique_items   : int  1 1 1 1 1 2 2 1 2 1 ...
 $ ICR            : num  0 0 0.48 0.48 0.48 ...
 $ Category       : Factor w/ 38 levels "0","1","10","11",..: 1 1 34 34 34 34 34 34 34 34 ...

I want to plot columns diffinscnd, total_clicks, unique_Category, unique_items, ICR and wanna output like this.

enter image description here

I tried hist() but output is wrong

> hist(data$diffinscnd)

enter image description here

How should I proceed?

Cœur
  • 37,241
  • 25
  • 195
  • 267
maira khan
  • 43
  • 1
  • 8
  • instead of printing the structure, you should print the output from dput(head(data)) – Khaynes Jan 08 '19 at 05:01
  • You can plot one column at a time using `hist()`, e.g. `hist(data$diffinscnd)`. If you need anything beyond that you should try to explain more in the question about exactly what you want. – Marius Jan 08 '19 at 05:23
  • Use `dput(head(df,20))` for a more meaningful example. – NelsonGon Jan 08 '19 at 05:30
  • @NelsonGon Error in UseMethod("depth") : no applicable method for 'depth' applied to an object of class "NULL" – maira khan Jan 08 '19 at 05:58
  • Someone else will help answer your question. Cheers! Next time please be explicit about what you want. Saves people time. What exactly is on the y-axis? Please ask your question in a way that leaves no room for doubt. Otherwise a lot of time is wasted. – NelsonGon Jan 08 '19 at 06:31
  • 1
    Possible duplicate of [ggplot2 - create a barplot for every column of a dataframe](https://stackoverflow.com/questions/52822840/ggplot2-create-a-barplot-for-every-column-of-a-dataframe) – markus Jan 08 '19 at 09:33

2 Answers2

1

To create histogram you can use hist() function from base R:

h <- hist(data$diffinscnd)

h1 <- hist(data$total_clicks)
markus
  • 25,843
  • 5
  • 39
  • 58
-1

With ggplot2, you can use this:

qplot(data$diffinscnd, geom = "histogram")

or using ggplot function:

ggplot(data, aes(x = diffinscnd)) + 
  geom_histogram()
Adela
  • 1,757
  • 19
  • 37
  • 1
    This is not a good answer because it does not do what OP asked for, uses dollar sign notation in `aes` which should be avoided. Besides, why would you not use code highlighting? – markus Jan 08 '19 at 09:43
  • Thanks for correcting, please suggest the right code. – Amit Maheshwari Jan 08 '19 at 09:48
  • Reshape the data to long format, then plot. And as I wrote, no need for `$` in `aes`. – markus Jan 08 '19 at 09:53
  • 1
    besides that, why not update your first answer instead of posting a new one? – Jaap Jan 08 '19 at 10:19