How can I rename the xlabel for this histogram?


Jaffet Leon

I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't:

cces$faminc_new1 = recode(cces$faminc_new,
                         "1" = "Less than $10,000",
                         "2" = "$10000 - $19,999",
                         "3" = "$20000 - $29,999",
                         "4" = "$30000 - $39,999",
                         "5" = "$40000 - $49,999",
                         "6" = "$50000 - $59,999",
                         "7" = "$60000 - $69,999",
                         "8" = "$70000 - $79,999",
                         "9" = "$80000 - $99,999",
                         "10"= "$100000 - $119,999",
                         "11"= "$120000 - $149,999",
                         "12"= "$150000 - $199,999",
                         "13"= "$200000 - $249,999",
                         "14"= "$250000 - $349,999",
                         "15"= "$350000 - $499,999",
                         "16"= "$500000 or more")

cces$educ1 = recode(cces$educ,
                   "1" = "1 No HS",
                   "2" = "2 HS graduate",
                   "3" = "3 Some college",
                   "4" = "4 2-year",
                   "5" = "5 4-year",
                   "6" = "6 Post-grad")


This scatter plot is perfect:enter image description here

But I can't rename the x tag for this history:

cces %>% ggplot(aes(x= faminc_new, colour = educ1, fill = educ1)) +
  geom_histogram() + scale_x_discrete(labels = c("1" = "Less than $10,000",
                         "2" = "20k",
                         "3" = "30k",
                         "4" = "40k",
                         "5" = "50",
                         "6" = "60",
                         "7" = "70k",
                         "8" = "80k",
                         "9" = "100k",
                         "10"= "120k",
                         "11"= "150k",
                         "12"= "200k",
                         "13"= "250k",
                         "14"= "350k",
                         "15"= "500k",
                         "16"= ">500k"))

enter image description here

faminc_new and educ are continuous, while faminc_new1 and educ1 are discrete.

How can I place the labels from faminc_new1 onto the x-labels of the histogram?

Su Ren

It appears that the expected result is a bar graph. So one option is to use geom_bar.

When using the histogram, there is an automatic break. So adding new tags manually won't work. If you want to stick with geom_histogramit, you must specify an interrupt.

Do the following after the introduction break.

mtcars %>% ggplot(aes(x= cyl, y= gear, colour = gear)) + 
  geom_bar(stat = "identity") +
  scale_x_continuous(labels = c("40k", "60k", "80k"), breaks = c(4, 6, 8))


mtcars %>% ggplot(aes(x = cyl, y = gear, colour = gear, fill = gear)) + 
  geom_histogram(stat = "identity") +
  scale_x_continuous(labels = c("40k", "60k", "80k"), breaks = c(4, 6, 8))

Related


How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I rename the xlabel for this histogram?

Jaffet Leon I'm making a histogram for a database about household income and education level and everything is fine, but when I try to rename the x labels, I simply can't: cces$faminc_new1 = recode(cces$faminc_new, "1" = "Less than $10

How can I fix the histogram

aa I am trying to draw a very simple histogram using python. Here is my code: from numpy import * from matplotlib.pyplot import* from random import* nums = [] N = 10 for i in range(N): a = randint(0,10) nums.append(a) bars= [0,1,2,3,4,5,6,7,8,9] hist(

How can I fix the histogram

aa I am trying to draw a very simple histogram using python. Here is my code: from numpy import * from matplotlib.pyplot import* from random import* nums = [] N = 10 for i in range(N): a = randint(0,10) nums.append(a) bars= [0,1,2,3,4,5,6,7,8,9] hist(

How can I rename bookmarks?

koni_raid When bookmarking, just add the page number. How does one rename bookmarks? Arkadiusz Drabczyk Press F9, go to Bookmarksthe side menu on the left, click the bookmark name, or right-click and select Rename Bookmark. There is also an introduction here .

How can I reduce the width of the histogram?

Itsuyama I have plotted a histogram of diagnostics, which I modeled as a Poisson distribution in python. I need to reduce the width of the rectangles in the output graph. I wrote the following line in python. I need the width reduction parameter for this line

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I reduce the width of the histogram?

Itsuyama I have plotted a histogram of diagnostics, which I modeled as a Poisson distribution in python. I need to reduce the width of the rectangles in the output graph. I wrote the following line in python. I need the width reduction parameter for this line

How can I make this histogram in ggplot/R?

Crimea Please find My data qbelow . I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment. q$best.respThere are three levels table(q$best.resp) 0 1 2 62 42

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I create a histogram in R?

sara I'm new to working in Unix, so I need help on how to put a histogram together using R in Linux environment? File: 48302 50 0 48303 46 0 48304 45 0 48305 41 15 48306 44 21 48307 74 0 48308 71 0 48309 35 19 48310 66 0 48311 26

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I make this histogram in ggplot/R?

Crimea Please find My data qbelow . I have two covariates: q$Studieand q$best.respcorresponding to each of the five different studies reporting the best response after a certain treatment. q$best.respThere are three levels table(q$best.resp) 0 1 2 62 42

How can I represent the classes on the histogram with colors?

Subhankar Nayak I have a column in a dataset which I represent with a pyplot.hist graph. Use grey as a trash can. Another column by which I want to divide the graph is called "Class". There are two categories (0 and 1) in the Category column. I would like to r

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I shift the histogram to the right?

alagnak32 I have a 1D array of histograms with bin boundaries: bins = np.arange(1, 6,2) data = np.array([1,2,3,4,4,4,3,2,3,3,3]) plt.hist(data, bins=bins, histtype='step') But I want to move the histogram horizontally by 1 unit to the right on the x-axis, how

How can I rename these files at once?

Arsalan I have a bunch of files and I want to rename them using regular expressions. I want to do this from the Linux command line. i have files report1.txt report2.txt report3.txt How do I rename these so they say myreport1.txt myreport2.txt myreport3.txt P

How can I rename the latest files in order?

stack john I have a powershell script (triggered by automation software). It effectively renames files by directory followed by an underscore, starting with a zero-sum sequential number. $i = 0 $folder = Any-path Get-ChildItem -Path $folder |ForEach-Object {$

How can I write a script to rename a file?

Richard Rublev I have files 263_V01_C07_R000_THx_BH_4096H.dat,263_V01_C07_R000_THY_BH_4096H.dat, wait, and I want to change all R000s to R011s. #!/bin/bash for file in *.dat; do if [[ "$file" =~ _THx_ ]]; then mv $file $file2 fi done But how to define fi

How can I rename a file to a substring in the filename?

Andres I am trying to rename a file in a directory with the substring "Episode.26" by truncating the words before and after the substring For example, "Escaflowne's Vision". Episode.26.Eternal.Love.1080p.Dual.Audio.Bluray [BC6DDF99] .MKV” The value found will

How can I rename a column that is an index?

Roland I want to rename the table column, but it is an index, hence the error. How can I fix this problem? ALTER TABLE <name> RENAME column <id> TO <newid>; Error: SQL0478N DROP, ALTER, TRANSFER OWNERSHIP... Roland untie: drop index alter table create index

How can I effectively rename my URL?

Gerback Lets say I'm creating a website with 4 pages about bananas, apples, tomatoes and carrots, so I currently have 4 .htmlfiles: bananas.php, apples.phpetc. I want my bananas.phpgig to look like this: domain.com/fruits/bananas-are-good/(as I have seen many