histogram

Changing the x-axis labels of a ggplot histogram

。_饼干妹妹 提交于 2021-02-05 08:11:43
问题 I have the following dataset (edited for readability): chol <- read.table(url("http://assets.datacamp.com/blog_assets/chol.txt"), header = TRUE) And I am creating a histogram of the data doing: ggplot(data=chol, aes(chol$AGE)) + geom_histogram() For a particular example I would like to change the x-labels however. Any thoughts on how I can pull this of? 回答1: To illustrate the answer (and better understand the question) a picture: > require(ggplot2) > chol <- read.table(url("http://assets

Is it possible to align x-axis ticks with corresponding bars in a matplotlib histogram?

北战南征 提交于 2021-02-05 07:51:33
问题 While plotting time-series date, i'm trying to plot the number of data points per hour: fig, ax = plt.subplots() ax.hist(x = df.index.hour, bins = 24, # draw one bar per hour align = 'mid' # this is where i need help rwidth = 0.6, # adding a bit of space between each bar ) I want one bar per hour, each hour labeled, so we set: ax.set_xticks(ticks = np.arange(0, 24)) ax.set_xticklabels(labels = [str(x) for x in np.arange(0, 24)]) The x-axis ticks are shown and labelled correctly, yet the bars

Is it possible to align x-axis ticks with corresponding bars in a matplotlib histogram?

独自空忆成欢 提交于 2021-02-05 07:51:14
问题 While plotting time-series date, i'm trying to plot the number of data points per hour: fig, ax = plt.subplots() ax.hist(x = df.index.hour, bins = 24, # draw one bar per hour align = 'mid' # this is where i need help rwidth = 0.6, # adding a bit of space between each bar ) I want one bar per hour, each hour labeled, so we set: ax.set_xticks(ticks = np.arange(0, 24)) ax.set_xticklabels(labels = [str(x) for x in np.arange(0, 24)]) The x-axis ticks are shown and labelled correctly, yet the bars

How to solve 'x' must be numeric in r?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-04 21:32:27
问题 I'm trying to make a histogram but I keep running into the an error message. Here is my code library(readxl) data <- read_excel("data.xls") View(data) attach(data) names(data) hist(data) This is my sample. I want to create a histogram the y-axis be 0-100, x-axis (safely, basic, limited, etc) the numbers (39,29,8,12,12) be in the graph. Does this help make sense? Safely Basic Limited Unimproved Open 39 29 8 12 12 Error in hist.default(data) : 'x' must be numeric What am I doing wrong? I don't

R cannot use hist() because “content not numeric” due to negative decimal numbers?

不羁的心 提交于 2021-02-04 19:49:26
问题 I am new to R and I am trying to draw a histogram using hist() of a list of 100,000 numbers like this -0.764 -0.662 -0.764 -0.019 0.464 0.668 0.464 but I cannot do it because R complains that the content is not numeric. This is what I've tried: I read the file using t <- read.table(file= "file.txt", sep = "\n", dec = ".", header = TRUE) , the data loads and looks well (I get the same values) I tried to make it numeric using as.numeric(c(t[,1])), sapply(t, as.numeric) , but I get completely

Overlapping ggplot2 histograms with different variables

淺唱寂寞╮ 提交于 2021-02-04 07:52:08
问题 If I had 2 different variables to plot as histograms, how would I do it? Take an example of this: data1 <- rnorm(100) data2 <- rnorm(130) If I want histograms of data1 and data2 in the same plot, is there a way of doing it? 回答1: You can get them in the same plot, by just adding another geom_histogram layer: ## Bad plot ggplot() + geom_histogram(aes(x=data1),fill=2) + geom_histogram(aes(x=data2)) However, a better idea would be to use density plots: d = data.frame(x = c(data1, data2), type=rep

Overlapping ggplot2 histograms with different variables

断了今生、忘了曾经 提交于 2021-02-04 07:49:13
问题 If I had 2 different variables to plot as histograms, how would I do it? Take an example of this: data1 <- rnorm(100) data2 <- rnorm(130) If I want histograms of data1 and data2 in the same plot, is there a way of doing it? 回答1: You can get them in the same plot, by just adding another geom_histogram layer: ## Bad plot ggplot() + geom_histogram(aes(x=data1),fill=2) + geom_histogram(aes(x=data2)) However, a better idea would be to use density plots: d = data.frame(x = c(data1, data2), type=rep

Drawing histogram of probability density function of a matrix in python [closed]

情到浓时终转凉″ 提交于 2021-01-29 20:12:30
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 days ago . Improve this question I have a 2D matrix of p-values. I want to draw a histogram of the pdf of this 2D matrix. How can I do that? 回答1: Just so you know: Seaborn's distplot does all of this. import seaborn as sns, numpy as np sns.set_palette("cividis"); np.random.seed(0) x = np.random.randn(100) ax =

Matplotlib histogram not counting correctly the number of values in each bin

独自空忆成欢 提交于 2021-01-29 12:43:46
问题 I am trying to make a very simple histogram with matplotlib.pyplot.hist, and it seems not to be counting properly the number of values in each bin. Here is my code: import numpy as np import matplotlib.pyplot as plt plt.hist([.2,.3,.5,.6],bins=np.arange(0,1.1,.1)) I am dividing the interval [0,1] in bins of width .1, so I should get four bars of height 1. But the output figure consists of only two bars of height 2: it is counting the .3 value as part of the [.2,.3) bin and, similarly, it is

How to draw an histogram with multiple categories in python

∥☆過路亽.° 提交于 2021-01-29 10:55:41
问题 I am a freshman in python, and I have a problem of how to draw a histogram in python. First of all, I have ten intervals that are divided evenly according to the length of flowers' petal, from min to max. Thus I can separate flowers into ten intervals based on petals. The number of flowers' kind is three, so I want to draw a histogram to describe the distribution of different kinds of flowers in different intervals(bins). And in the same bin, different flowers have different colors. I know