histogram

How to separate the two leftmost bins of a histogram in R

耗尽温柔 提交于 2019-11-29 14:05:06
Suppose I need to plot a dataset like below: set.seed(1) dataset <- sample(1:7, 1000, replace=T) hist(dataset) As you can see in the plot below, the two leftmost bins do not have any space between them unlike the rest of the bins. I tried changing xlim, but it didn't work. Basically I would like to have each number (1 to 7) represented as a bin, and additionally, I would like any two adjacent bins to have space beween them...Thanks! The best way is to set the breaks argument manually. Using the data from your code, hist(dataset,breaks=rep(1:7,each=2)+c(-.4,.4)) gives the following plot: The

How to plot histogram/ frequency-count of a vector with ggplot?

≯℡__Kan透↙ 提交于 2019-11-29 13:52:16
I want to plot with ggplot the frequency of values from a numeric vector. With plot() is quite straight forward but I can't get the same result with ggplot . library(ggplot2) dice_results <- c(1,3,2,4,5,6,5,3,2,1,6,2,6,5,6,4) hist(dice_results) ggplot(dice_results) + geom_bar() # Error: ggplot2 doesn't know how to deal with data of class numeric Should I create a dataframe for ggplot() to plot my vector? Please look at the help page ?geom_histogram . From the first example you may find that this works. qplot(as.factor(dice_results), geom="histogram") Also look at ?ggplot . You will find that

Making a histogram of string values in python

馋奶兔 提交于 2019-11-29 13:48:38
OK so I have six possible values for data to be which are '32', '22', '12', '31', '21' and '11'. I have these stored as strings. Is it possible for python to sort through the data and just make six bins and show how many of each I have? Or do the inputs to a histogram HAVE to be numerical? data = ['32', '22', '12', '32', '22', '12', '31', '21', '11'] dict((x, data.count(x)) for x in data) Result {'11': 1, '12': 2, '21': 1, '22': 2, '31': 1, '32': 2} Did you consider using collections.Counter ? # python 2.7 >>> l = ['32', '22', '12', '31', '21', '11', '32'] >>> import collections >>>

How to use the function curve in [R] to graph a normal curve?

微笑、不失礼 提交于 2019-11-29 13:46:58
I'm trying to make a histogram in [R], and the normal curve that describes the histogram as follows: w<-rnorm(1000) hist(w,col="red",freq=F,xlim=c(-5,5)) curve(dnorm(w),-5,5,add=T,col="blue") But when I try to plot the normal curve by curve function shows me the following error: Error en curve(dnorm(w), -5, 5, add = T, col = "blue") : 'expr' must be a function, or a call or an expression containing 'x' What am I doing wrong? You just need to drop the "w" argument to dnorm in curve : w<-rnorm(1000) hist(w,col="red",freq=F,xlim=c(-5,5)) curve(dnorm,-5,5,add=T,col="blue") To use something other

Draw a frequency histogram in C++/OpenCV

天大地大妈咪最大 提交于 2019-11-29 12:27:35
An array of frequency is created. int arr[10]; arr[0] = 24; arr[1] = 28; arr[2] = 23; arr[3] = 29; //and so on How do i draw a histogram using OpenCV in C++ based on the array? Miki OpenCV is not really suited for plotting. However, for simple histograms, you can draw a rectangle for each column (eventually with alternating colors) This is the code: #include <opencv2\opencv.hpp> #include <algorithm> using namespace std; using namespace cv; void drawHist(const vector<int>& data, Mat3b& dst, int binSize = 3, int height = 0) { int max_value = *max_element(data.begin(), data.end()); int rows = 0;

Make y-axis logarithmic in histogram using R [duplicate]

大憨熊 提交于 2019-11-29 12:13:03
问题 This question already has an answer here: Histogram with Logarithmic Scale and custom breaks 7 answers Hi I'm making histogram using R, but the number of Y axis is so large that I need to turn it into logarithmic.See below my script: hplot<-read.table("libl") hplot pdf("first_end") hist(hplot$V1, breaks=24, xlim=c(0,250000000), ylim=c(0,2000000),main="first end mapping", xlab="Coordinates") dev.off() So how should I change my script? thx 回答1: You can save the histogram data to tweak it before

How do you use hist to plot relative frequencies in R?

[亡魂溺海] 提交于 2019-11-29 12:08:08
问题 How do you use hist() to plot relative frequencies in R? If I do the following, I will get a density plot, but I want a relative frequency plot: a <- c(0,0,0,1,1,2) hist(a, freq=FALSE) I want to see a histogram with the following relative frequencies: .5 for 0 to 1, .33 for 1 to 2, and .166 for 2 to 3. 回答1: you can try using the histogram() function in lattice a <- c(0,0,0,1,1,2) library(lattice) histogram(a) defaults to percent. 回答2: I've added a new function to the HistogramTools package on

How to apply histogram on dependent data in R?

浪子不回头ぞ 提交于 2019-11-29 09:02:08
I want to visualise the proportional data (Nij/n) about the sinus (independent) and arr/AHB (dependent variable) cases in females and males by R. ggplot2 approach and any other is welcome! Pseudocode histogram of the second and third columns for the groups N11.1, ..., N32.1 Code N11.1 N22.1 N33.1 N44.1 N21.1 N31.1 N32.1 Sinus 1.0 0.0 0.0 0.0 0.0 0.0 12.0 Arr/AHB 1.0 0.0 0.0 0.1 0.0 0.0 20.9 N11.1 N22.1 N33.1 N44.1 N21.1 N31.1 N32.1 Sinus 1.0 0.0 0.0 0.0 0.0 0.0 4.0 Arr/AHB 1.0 0.0 0.0 0.0 0.0 0.0 24.0 The first column has the row.names. Code with the data library("ggplot2") data.female <-

Find dominant color on an image

家住魔仙堡 提交于 2019-11-29 08:24:38
问题 I want to find dominant color on an image. For this, I know that I should use image histogram. But I am not sure of image format. Which one of rgb, hsv or gray image, should be used? After the histogram is calculated, I should find max value on histogram. For this, should I find below maximum binVal value for hsv image? Why my result image contains only black color? float binVal = hist.at<float>(h, s); EDIT : I have tried the below code. I draw h-s histogram. And my result images are here. I

gnuplot histogram: How to put values on top of bars

拟墨画扇 提交于 2019-11-29 07:22:27
I have the following data: 1 3215 2 321 ... 31_60 59 60+ 32 I would like to generate histogram using gnuplot and put the value of bar on top of it. Here is the gnuplot command I tried to create histogram: set style data histogram set xtics rotate plot 'file.dat' using 2:xtic(1) Can someone tell me how to add values on top of the bars generated? I found the following link related histogram ( http://gnuplot-tricks.blogspot.com/2009/10/more-on-histograms.html ), but didnt get what its doing exactly. With this as some sample data file Data.dat : 1 10 2 20 3 15 4 16 5 19 6 5 You could run this