scale_fill_gradient in GGPlot is not workingHow to make a great R reproducible exampleggplot: How to change facet labels?Choosing between qplot() and ggplot() in ggplot2Turning off some legends in a ggplotHow to change legend title in ggplotremove legend title in ggplotRemove all of x axis labels in ggplotChoropleth or Thematic map creation from number of points within Shapefile polygonRemove legend ggplot 2.2ggplot - Create a border overlay on top of mapggplot: get discrete legend with scale_fill_gradient

Ideas for 3rd eye abilities

Is every set a filtered colimit of finite sets?

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Pristine Bit Checking

Is there a familial term for apples and pears?

Why do we use polarized capacitors?

Are objects structures and/or vice versa?

Need help identifying/translating a plaque in Tangier, Morocco

Why is my log file so massive? 22gb. I am running log backups

Is there any use for defining additional entity types in a SOQL FROM clause?

Could a US political party gain complete control over the government by removing checks & balances?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

What to wear for invited talk in Canada

What is the command to reset a PC without deleting any files

Calculate Levenshtein distance between two strings in Python

Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?

How to manage monthly salary

"listening to me about as much as you're listening to this pole here"

What is the offset in a seaplane's hull?

Is there a name of the flying bionic bird?

Extreme, but not acceptable situation and I can't start the work tomorrow morning

How would photo IDs work for shapeshifters?

Is a vector space a subspace of itself?

COUNT(*) or MAX(id) - which is faster?



scale_fill_gradient in GGPlot is not working


How to make a great R reproducible exampleggplot: How to change facet labels?Choosing between qplot() and ggplot() in ggplot2Turning off some legends in a ggplotHow to change legend title in ggplotremove legend title in ggplotRemove all of x axis labels in ggplotChoropleth or Thematic map creation from number of points within Shapefile polygonRemove legend ggplot 2.2ggplot - Create a border overlay on top of mapggplot: get discrete legend with scale_fill_gradient






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















I am trying to use ggplot to plot stream height gage locations from a dataframe (in Special Features or SF format) on top of Nebraska county shapefile data which was also read into R as a SF dataframe. The scale_fill_gradient piece of my code is not working and filling in the counties with a gradient.



I will show my code below to make it easier to understand:



#Read in Counties shapefile into an sf dataframe, filtering for just Nebraska counties
CountiesShapefile <- st_read('cb_2017_us_county_20m.shp')%>%filter(STATEFP == 31)

#Read in Stream Gage Locations
NWIS <- read.csv('NWIS_SiteInfo_NE_RAW.csv')

#Convert the Stream Gage Dataframe to a SF Dataframe
NWISsf <- st_as_sf(NWIS,
coords = c('dec_long_va', 'dec_lat_va'),
crs = 4269)

#Read in Gage Flow Data
NWISFlow <- read.csv('NWIS_SiteFlowData_NE_RAW.csv')

#Using a Left Join to combine Stream Gage and Gage Flow Dataframes
NWISJoinClean <- left_join(NWIS, NWISFlow, by='station_nm')

#Convert Joined DF back to SF Dataframe
NWISJoinCleansf <- st_as_sf(NWISJoinClean,
coords = c('dec_long_va','dec_lat_va'),
crs = 4269)

#Use ggplot to plot the Gage Locations on top of the counties(this one worked)
GagePlot <- ggplot() +
geom_sf(data = CountiesShapefile, col='purple') +
geom_sf(data = NWISJoinCleansf, col='blue')

#Use ggplot to plot gage sites on top of counties AND show the magnitude of gage
#height by color, shape, or other visualization techniques(issue is here)
GagePlot2 <- ggplot() +
geom_sf(data=CountiesShapefile, col='black') +
geom_sf(data=NWISJoinCleansf, aes(fill=gage_ht))+
scale_fill_gradient("gage_ht",low='red', high='white')


"gage_ht" is a column in the NWISJoinCleansf dataframe, and it is a
number object. I got the same exact graph as I did for the code without
the scale_fill_gradient. My goal is to have the counties shaded by
gradient, with the darkest colors for the highest stream gage heights.
Does anyone know what I am doing wrong?



Edit:
I added the aesthetic to the second geom_sf line and it still didn't work.
Head of NWISJoinCleansf data frame










share|improve this question



















  • 1





    You haven't mapped any aesthetic to fill in your code. Try adding aes(fill = gage_ht) to geomsf(data = NWISJoinCleansf, ...). If that doesn't work, do consider making your problem reproducible by including a sample of your data in your question, e.g. dput(head(NWISJoinCleansf, 20)) or something like that.

    – Z.Lin
    Mar 22 at 2:46











  • While it's commendable that you tried to include a data sample, an image of data is not data. Please paste in the actual console output from dput(...). (If you can't get that to look like well-formatted code, someone will probably come along & edit it for you.)

    – Z.Lin
    Mar 22 at 15:45

















-1















I am trying to use ggplot to plot stream height gage locations from a dataframe (in Special Features or SF format) on top of Nebraska county shapefile data which was also read into R as a SF dataframe. The scale_fill_gradient piece of my code is not working and filling in the counties with a gradient.



I will show my code below to make it easier to understand:



#Read in Counties shapefile into an sf dataframe, filtering for just Nebraska counties
CountiesShapefile <- st_read('cb_2017_us_county_20m.shp')%>%filter(STATEFP == 31)

#Read in Stream Gage Locations
NWIS <- read.csv('NWIS_SiteInfo_NE_RAW.csv')

#Convert the Stream Gage Dataframe to a SF Dataframe
NWISsf <- st_as_sf(NWIS,
coords = c('dec_long_va', 'dec_lat_va'),
crs = 4269)

#Read in Gage Flow Data
NWISFlow <- read.csv('NWIS_SiteFlowData_NE_RAW.csv')

#Using a Left Join to combine Stream Gage and Gage Flow Dataframes
NWISJoinClean <- left_join(NWIS, NWISFlow, by='station_nm')

#Convert Joined DF back to SF Dataframe
NWISJoinCleansf <- st_as_sf(NWISJoinClean,
coords = c('dec_long_va','dec_lat_va'),
crs = 4269)

#Use ggplot to plot the Gage Locations on top of the counties(this one worked)
GagePlot <- ggplot() +
geom_sf(data = CountiesShapefile, col='purple') +
geom_sf(data = NWISJoinCleansf, col='blue')

#Use ggplot to plot gage sites on top of counties AND show the magnitude of gage
#height by color, shape, or other visualization techniques(issue is here)
GagePlot2 <- ggplot() +
geom_sf(data=CountiesShapefile, col='black') +
geom_sf(data=NWISJoinCleansf, aes(fill=gage_ht))+
scale_fill_gradient("gage_ht",low='red', high='white')


"gage_ht" is a column in the NWISJoinCleansf dataframe, and it is a
number object. I got the same exact graph as I did for the code without
the scale_fill_gradient. My goal is to have the counties shaded by
gradient, with the darkest colors for the highest stream gage heights.
Does anyone know what I am doing wrong?



Edit:
I added the aesthetic to the second geom_sf line and it still didn't work.
Head of NWISJoinCleansf data frame










share|improve this question



















  • 1





    You haven't mapped any aesthetic to fill in your code. Try adding aes(fill = gage_ht) to geomsf(data = NWISJoinCleansf, ...). If that doesn't work, do consider making your problem reproducible by including a sample of your data in your question, e.g. dput(head(NWISJoinCleansf, 20)) or something like that.

    – Z.Lin
    Mar 22 at 2:46











  • While it's commendable that you tried to include a data sample, an image of data is not data. Please paste in the actual console output from dput(...). (If you can't get that to look like well-formatted code, someone will probably come along & edit it for you.)

    – Z.Lin
    Mar 22 at 15:45













-1












-1








-1








I am trying to use ggplot to plot stream height gage locations from a dataframe (in Special Features or SF format) on top of Nebraska county shapefile data which was also read into R as a SF dataframe. The scale_fill_gradient piece of my code is not working and filling in the counties with a gradient.



I will show my code below to make it easier to understand:



#Read in Counties shapefile into an sf dataframe, filtering for just Nebraska counties
CountiesShapefile <- st_read('cb_2017_us_county_20m.shp')%>%filter(STATEFP == 31)

#Read in Stream Gage Locations
NWIS <- read.csv('NWIS_SiteInfo_NE_RAW.csv')

#Convert the Stream Gage Dataframe to a SF Dataframe
NWISsf <- st_as_sf(NWIS,
coords = c('dec_long_va', 'dec_lat_va'),
crs = 4269)

#Read in Gage Flow Data
NWISFlow <- read.csv('NWIS_SiteFlowData_NE_RAW.csv')

#Using a Left Join to combine Stream Gage and Gage Flow Dataframes
NWISJoinClean <- left_join(NWIS, NWISFlow, by='station_nm')

#Convert Joined DF back to SF Dataframe
NWISJoinCleansf <- st_as_sf(NWISJoinClean,
coords = c('dec_long_va','dec_lat_va'),
crs = 4269)

#Use ggplot to plot the Gage Locations on top of the counties(this one worked)
GagePlot <- ggplot() +
geom_sf(data = CountiesShapefile, col='purple') +
geom_sf(data = NWISJoinCleansf, col='blue')

#Use ggplot to plot gage sites on top of counties AND show the magnitude of gage
#height by color, shape, or other visualization techniques(issue is here)
GagePlot2 <- ggplot() +
geom_sf(data=CountiesShapefile, col='black') +
geom_sf(data=NWISJoinCleansf, aes(fill=gage_ht))+
scale_fill_gradient("gage_ht",low='red', high='white')


"gage_ht" is a column in the NWISJoinCleansf dataframe, and it is a
number object. I got the same exact graph as I did for the code without
the scale_fill_gradient. My goal is to have the counties shaded by
gradient, with the darkest colors for the highest stream gage heights.
Does anyone know what I am doing wrong?



Edit:
I added the aesthetic to the second geom_sf line and it still didn't work.
Head of NWISJoinCleansf data frame










share|improve this question
















I am trying to use ggplot to plot stream height gage locations from a dataframe (in Special Features or SF format) on top of Nebraska county shapefile data which was also read into R as a SF dataframe. The scale_fill_gradient piece of my code is not working and filling in the counties with a gradient.



I will show my code below to make it easier to understand:



#Read in Counties shapefile into an sf dataframe, filtering for just Nebraska counties
CountiesShapefile <- st_read('cb_2017_us_county_20m.shp')%>%filter(STATEFP == 31)

#Read in Stream Gage Locations
NWIS <- read.csv('NWIS_SiteInfo_NE_RAW.csv')

#Convert the Stream Gage Dataframe to a SF Dataframe
NWISsf <- st_as_sf(NWIS,
coords = c('dec_long_va', 'dec_lat_va'),
crs = 4269)

#Read in Gage Flow Data
NWISFlow <- read.csv('NWIS_SiteFlowData_NE_RAW.csv')

#Using a Left Join to combine Stream Gage and Gage Flow Dataframes
NWISJoinClean <- left_join(NWIS, NWISFlow, by='station_nm')

#Convert Joined DF back to SF Dataframe
NWISJoinCleansf <- st_as_sf(NWISJoinClean,
coords = c('dec_long_va','dec_lat_va'),
crs = 4269)

#Use ggplot to plot the Gage Locations on top of the counties(this one worked)
GagePlot <- ggplot() +
geom_sf(data = CountiesShapefile, col='purple') +
geom_sf(data = NWISJoinCleansf, col='blue')

#Use ggplot to plot gage sites on top of counties AND show the magnitude of gage
#height by color, shape, or other visualization techniques(issue is here)
GagePlot2 <- ggplot() +
geom_sf(data=CountiesShapefile, col='black') +
geom_sf(data=NWISJoinCleansf, aes(fill=gage_ht))+
scale_fill_gradient("gage_ht",low='red', high='white')


"gage_ht" is a column in the NWISJoinCleansf dataframe, and it is a
number object. I got the same exact graph as I did for the code without
the scale_fill_gradient. My goal is to have the counties shaded by
gradient, with the darkest colors for the highest stream gage heights.
Does anyone know what I am doing wrong?



Edit:
I added the aesthetic to the second geom_sf line and it still didn't work.
Head of NWISJoinCleansf data frame







r ggplot2 sf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 14:04







Gaby

















asked Mar 22 at 1:29









GabyGaby

23




23







  • 1





    You haven't mapped any aesthetic to fill in your code. Try adding aes(fill = gage_ht) to geomsf(data = NWISJoinCleansf, ...). If that doesn't work, do consider making your problem reproducible by including a sample of your data in your question, e.g. dput(head(NWISJoinCleansf, 20)) or something like that.

    – Z.Lin
    Mar 22 at 2:46











  • While it's commendable that you tried to include a data sample, an image of data is not data. Please paste in the actual console output from dput(...). (If you can't get that to look like well-formatted code, someone will probably come along & edit it for you.)

    – Z.Lin
    Mar 22 at 15:45












  • 1





    You haven't mapped any aesthetic to fill in your code. Try adding aes(fill = gage_ht) to geomsf(data = NWISJoinCleansf, ...). If that doesn't work, do consider making your problem reproducible by including a sample of your data in your question, e.g. dput(head(NWISJoinCleansf, 20)) or something like that.

    – Z.Lin
    Mar 22 at 2:46











  • While it's commendable that you tried to include a data sample, an image of data is not data. Please paste in the actual console output from dput(...). (If you can't get that to look like well-formatted code, someone will probably come along & edit it for you.)

    – Z.Lin
    Mar 22 at 15:45







1




1





You haven't mapped any aesthetic to fill in your code. Try adding aes(fill = gage_ht) to geomsf(data = NWISJoinCleansf, ...). If that doesn't work, do consider making your problem reproducible by including a sample of your data in your question, e.g. dput(head(NWISJoinCleansf, 20)) or something like that.

– Z.Lin
Mar 22 at 2:46





You haven't mapped any aesthetic to fill in your code. Try adding aes(fill = gage_ht) to geomsf(data = NWISJoinCleansf, ...). If that doesn't work, do consider making your problem reproducible by including a sample of your data in your question, e.g. dput(head(NWISJoinCleansf, 20)) or something like that.

– Z.Lin
Mar 22 at 2:46













While it's commendable that you tried to include a data sample, an image of data is not data. Please paste in the actual console output from dput(...). (If you can't get that to look like well-formatted code, someone will probably come along & edit it for you.)

– Z.Lin
Mar 22 at 15:45





While it's commendable that you tried to include a data sample, an image of data is not data. Please paste in the actual console output from dput(...). (If you can't get that to look like well-formatted code, someone will probably come along & edit it for you.)

– Z.Lin
Mar 22 at 15:45












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291598%2fscale-fill-gradient-in-ggplot-is-not-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291598%2fscale-fill-gradient-in-ggplot-is-not-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript