According to The Most Popular Keys of All Music on Spotify, an analysis of their song library, sharp keys are more common than flat keys.
It's an artifact of Spotify's analysis. Notice that this chart shows no songs written in a flat key. Therefore, without a doubt, the chart is simply using "F♯" to mean "F♯ or G♭," "A♯" to mean "A♯ or B♭," and so forth.
In particular, B♭ major (with a key signature of ♭♭ – two flats) is definitely much more common than A♯ (with a key signature of 𝄪𝄪𝄪♯♯♯♯ – ten sharps, which is to say, three double sharps and four single sharps). But the chart shows B♭ as though it were A♯.
While there are certainly questions about how all of this data was classified, it's not surprising to me that the most popular keys tend slightly toward the sharp side (G, D, and A), with flat keys like F and B-flat ("A-sharp") turning up with smaller percentages.
I assume much of Spotify's catalog is popular music. Guitars and electric basses are rather dominant instruments there, which tend to be biased slightly toward sharp keys like G, D, and A in their typical tunings. (That is, it is often somewhat easier for beginners to play the basic notes and chords in these keys, due to more open strings and the use of only the first few frets.) Obviously keys near to C major on the circle of fifths are also relatively easy to play on piano/keyboard, another central instrument in pop music.
That leaves the mystery of why C#/D-flat and G#/A-flat are also ranked somewhat highly after the central keys of C, G, D, and A. My immediate question is how Spotify determined the key for songs that have more than one key. If they looked at the final key, many pop songs contain a final modulation that moves up by a half step, which would take C and G to D-flat and A-flat. That's speculation, but one potential explanation. (Of course, I'm putting a lot of faith that Spotify's key-finding algorithm is accurate, which it may not be.)
But why the most popular keys tend toward the slightly sharper side seems clear: they work reasonably well on both guitar and piano.
Firstly, the data is presented in such a way that it is difficult to see if what they are alleging is true. Secondly, they have no key signatures with flats in their names. I'll give them a pass on six sharps (though this could be just as well written as six flats) but A# major is ridiculous.
I've tabulated the data below. it totals up to 99.8%. I'm not sure if that's my maths or their rounding error. I've totalled up the cases for up to 5 sharps or flats. The cases 0 sharps/flats and 6 sharps/flats do not belong to either the sharp key or flat key category.
For minor keys there is a bias toward sharp keys 14.2% vs flat keys 13.8% but this is vanishingly small. For major keys there is a bias toward sharp keys 31.7% vs flat keys 21.5%. Removing G major (10.7%) from the analysis would cancel this difference, so we can say that on average music written in a major key contains on average about 1/2 a sharp.
5b Bbm* 3.2% Dbmaj* 6.0% 4b Fm 3.0% Abmaj* 4.3% 3b Cm 2.4% Ebmaj* 2.4% 2b Gm 2.6% Bbmaj* 3.5% 1b Dm 2.6% Fmaj 5.3% TOTAL b 13.8% 21.5% Natural Am 4.8% Cmaj 10.2% 1# Em 4.2% Gmaj 10.7% 2# Bm 4.2% Dmaj 8.7% 3# F#m 2.5% Amaj 6.1% 4# C#m 2.1% Emaj 3.6% 5# G#m 1.2% Bmaj 2.6% TOTAL # 14.2% 31.7% 6# D#m 0.9% F#maj 2.7% GRAND TOTAL 33.7% 66.1% Keys marked with a * are shown as sharp keys in the original data, but are better and more commonly written as flat keys.
The bias is, as noted in the article itself, probably due to the instruments used. Older music with wind and brass may favour flat keys, but Spotify will contain a lot of guitar music, and guitar is a little easier to play in sharp keys, particularly in major.
On guitar Amaj, Emaj and Dmaj are among the easiest chords to play. The Relative minors F#m, C#m and Bm are all barre chords however. I think this explains why the bias towards sharp keys occurs only in major but not in minor. For playing in Am/Cmaj the chords Am, Em and Dm are also easy, and there are other easy chord shapes for Cmaj and Gmaj (but Fmaj requires a barre, which can be avoided by playing in the key of Gmaj instead of Cmaj.) There are many songs written for guitar that only work with open string chords, not barre chords, and therefore often can only be played as intended in the key of Gmaj or Amaj for example.
Simple answer - they've labelled keys in an unusual manner. G♯ is normally written as A♭; A♯ more often as B♭. That's for starters. Redefine in the more commonly used key names, and the proportions change.
At least it's not like some guitar sites, which eschew flats altogether, and only live in a world of sharps!
To answer the question posed in the title, I have noticed three things that gently influence the choice of key.
I don't have authoritative sources to confirm this - it is just my opinion.
In many contexts which describe audio pitches, it is common to use the names "C C# D D# E F F# G G# A A# B" [except in German, where the last three notes would be "A B H"]. The chart is most likely produced by processing the songs, identifying the apparent key note and primary tonality, and then determining the pitch of the key note using the above names. Listening to a piece of music, it would be impossible to distinguish between B and Cb, F# and Gb, or C# and Db, or between the associated pairs of relative minor keys. Using A# to refer to Bb may seem unusual, but it helps to make clear that the chart is only identifying the audio pitches associated with the key notes, rather than making any judgment as to how they are written.
Aside from the notational issue of "no flat keys," the data as presented isn't consistent with common sense.
There are only a handful of classical pieces in D sharp minor in the entire repertoire (I challenge anyone to name more than five), and nobody is likely to write anything for guitar in either D sharp or E flat minor, so Spotify's claim that almost 1 in 100 pieces is in that key is simply unbelievable.
More likely, there are about 1 in 100 pieces that are in either D minor or E minor, but were not played at A=440 pitch, and Spotify's software mislabelled them.
Since there is no reason to believe the other groups are any more accurate, the whole chart is a work of fiction unless somebody can prove otherwise.