Filling histogram by column of color names

I have a function that combines data sets and assigns colors to each like the code seen below

x1 <- rep(1:10, each = 3, times = 3) x2 <- rep(1:7, each = 7, times = 2) x3 <- rep(6:9, each = 11, times = 4) y1 <- rep(1:5, each = 2, times = 9) y2 <- rep(1:14, times = 7) y3 <- rep(1:11, times = 16) color1 <- rep("blue", times = length(x1)) color2 <- rep("red", times = length(x2)) color3 <- rep ("green", times = length(x3)) data1 <- cbind(x1, y1, color1) data2 <- cbind(x2, y2, color2) data3 <- cbind(x3, y3, color3) alldata <- data.frame(rbind(data1, data2, data3)) colnames(alldata) <- c("x", "y", "color") ggplot(data = alldata, aes(x=x), position = "dodge") + geom_histogram(fill = alldata$color) ggplot(data = alldata, aes(x=x, y=y)) + geom_point(colour = alldata$color)

I was wondering why the colors aren't being assigned to the histogram, but they are being supplied to the points of the scatter plot.

The error I'm getting is

Error: Incompatible lengths for set aesthetics: fill

Essentially the data is being grouped by color, and I want the color assigned to each group to be the color represented in the histogram.

-------------Problems Reply------------

You want to map your color variable to fill and use those values without scaling:

ggplot(alldata, aes(x=x, fill = color)) +
geom_histogram(position = "dodge") +
scale_fill_identity()

Category:r Views:0 Time:2019-03-14
Tags: ggplot2

Related post

  • Make WPF ComboBoxes fill a whole column width 2009-05-05

    I'm having problems making a ComboBox stretch to fill the whole column width in a GridViewColumn. It should also resize when the column is resized. In the following example I have a StackPanel with a ComboBox inside. This is set to stretch and will i

  • Get used color names from image 2010-04-05

    I would like to check what colors is present in a image. This will be stored in the database and used for a search form. (red=1, green=1, blue=0, yellow=1, black=1, white=1 etc.) img = Magick::Image.read('phosto-file.jpg').first img = img.quantize(10

  • How to create openCV image of certain (R, G, B) color and get that color name? 2010-12-01

    I need to create an image filled with some (R,G,B) color. And get that color name like some (R,G,B) = black or red and so on. Can we do such thing with openCV, and how to do it? --------------Solutions------------- opencv doesn't create images with a

  • Winforms combobox containing system color names? 2011-03-15

    What's the easiest way to list system drawing color names in a combobox? (we don't need a full blown color picker or to see the any coloring, just the color names in black and white) --------------Solutions------------- Something like this: ComboBox

  • PHP - get color name from rgb 2011-09-29

    i work now with GD library on PHP and i'm trying to get the pixel color name ,i mean : green , red , blue , etc... i'm getting the color this way : $rgb = ImageColorAt($image, $X, $y); $r = ($rgb >> 16) & 0xFF ; $g = ($rgb >> 8) &

  • How do I Convert Text to Columns and slit names 2012-09-17

    I am trying split first and last names that are in one column into two columns one for first name and a column for last name. I once Split names by using the Convert Text to Columns Wizard. Is there a tool like this for Excel for the Mac? -----------

  • Excel 2010: color names not popping up when selecting format color 2013-01-13

    In Excel 2010, I need to use a specific fill color, but the color names don't pop up the way they should when I hover. How can I turn this feature on? --------------Solutions------------- Hi, Welcome to Microsoft Office Community and thanks for posti

  • Is there a way to see the color that will display for a .NET color name? 2009-02-10

    I'm using System.Drawing.Color, is there anything in Visual Studio that can display the color for the name? For example if I used Color.Cornsilk what would color would be displayed? --------------Solutions------------- The Windows Forms properties wi

  • How can I reference columns by their names in python calling SQLite? 2009-02-23

    I have some code which I've been using to query MySQL, and I'm hoping to use it with SQLite. My real hope is that this will not involve making too many changes to the code. Unfortunately, the following code doesn't work with SQLite: cursor.execute(qu

  • Is this a bug with SharePoint Column/Field internal names in MOSS 2007 2009-02-27

    There seems to be a bug with columns in SharePoint MOSS 2007. It allows you to add a new column say 'Team'. When you add this it stores the internal name as 'Team' which makes sense. The business then decide that 'Team' should be called 'Workstream',

  • Javascript function to convert color names to hex codes 2009-10-15

    Is there a built-in function that would convert a color by name into its hex representation? Like I want to pass 'white' and receive '#FFFFFF'. I really want to avoid coding all hundred if's myself :) --------------Solutions------------- No, but usin

  • Localized System.Windows.Media.Color name 2010-02-10

    The standard color names are english names, ok. But my Application is german so I would like to have the color names in my ComboBox as german names. Instead of "Blue", "Yellow", etc. I would like to have "Blau", "Gelb", etc. Is there a function that

  • Why does my Tk application error out with "unknown color name white"? 2010-02-23

    I just installed tkdiff on a ubuntu machine and when I try and run the program I get the following error: actual font: -family {DejaVu Sans Mono} -size -12 -weight normal -slant roman -underline 0 -overstrike 0 Error in startup script: unknown color

  • How to convert RGB value to color name in Silverlight 4.0? 2010-05-04

    The code : Dim myColor As Color = Colors.Red Dim colorName As String = myColor.ToString() Results in : #FFFF0000 when printing colorName to screen. Is it possible to get the color name in Silverlight without making a select case on the RGB values? --

  • Proper color names from colordialog 2010-06-01

    Whenever I run this, and open the color dialog, there are many colors that do not having a proper name, the listbox will show something like "ffff8000"(Orange-Yellow). Is there another way of pushing the proper name? Is there a proper Color Name libr

  • Function that converts hex color values to an approximate color name? 2010-06-07

    I don't suppose anyone knows of a function (PHP, preferably) that can take a hex color code and give an approximate color name for that hex value. I don't need a solution with 100s of colors. Even if it just amounted to the colors white, black, red,

  • Sorting datatable column by day name 2010-06-09

    I have a datatable with day name column. I want to sort this column by day name e.g. if I have [Friday, Monday,Sunday] sorting should return [Monday ,Friday, Sunday] (ascending) and [Sunday,Friday, Monday] (descending). I tried to use custom sorting

  • How can I find the underlying column and table name for an Oracle view? 2010-06-23

    This sounds like it should be simple to do but not so! There is no Oracle (meta-data) view that I can find that gives the underlying column and table name for an Oracle view column. The only way I have found of doing it is to parse the view source SQ

  • Are there any cons to using color names in place of color codes in CSS? 2010-07-12

    For example writing red is more efficient than #cc0000. It has less characters, takes up less space, and is easier to remember. Are there any down sides to using color names over hex codes or RGB values? This includes programming in a multi-developer

  • How to select columns that have name beginning with same prefix? 2010-10-15

    Using PostgreSQL 8.1.11, is there a way to select a set of columns that have name beginning with same prefix. Suppose we have columns : PREFIX_col1, PREFIX_col2, ... Is it possible to do a request like : SELECT 'PREFIX_*' FROM mytable; Which of cours

  • Java color code convert to color name 2010-11-08

    Can convert a color rgb code into color name? like blue yellow red --------------Solutions------------- Populate a list of "known" colors. For each known color compute: rgbDistance = Math.abs(myColor.getRed() - colorI.getRed() + Math.abs(myColor.getG

  • Batch COLOR script that accepts Color-names, Decimals and Hex Parameters 2010-11-19

    I just finished my a Batch COLOR script that accepts Color-names, Decimals and Hex Parameters. This script works exactly like the MS-Color command but it also accepts decimals and color-names. Run this script without perimeters for a full description

  • find all tables containing column with specified name 2011-01-31

    Is it possible that I can query for names of all tables which contain column with name Like %myName% --------------Solutions------------- SELECT c.name AS ColName, t.name AS TableName FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id

  • MATLAB: convert color name to RGB 3 element vector 2011-02-07

    In many matlab plotting functions, you can specify the color as either a string or as a 3 element vector that directly lists the red, green, and blue values For instance, these two statements are equivalent plot (x,y,'Color','r'); plot (x,y,'Color',

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.406 (s). 11 q(s)