I'm not a historian, but as a Brazilian I can give you some insight with the limited knowledge i have.
Brazil was, as the United States used to be, several colonies, ruled by nobility, styled Capitães (Captains). As they developed, some of them have indeed tried to become independant from Portugal, but have failed doing it so. They were later extinct, and the colonial government was centralized in Salvador.
At the time of the Napoleonic wars, Portugal was allied with Britain, and was opposed to France. With the advance of Napoleon in the Iberian Peninsula, Portugal's Royal family came to Brazil to avoid being captured by the French. While here, the royal regent John VI soon-to-be-king elevated the status of Brazil from colony to kingdom. So, for a time, Brazil and Portugal were united kingdoms under the same monarch, first Maria very briefly, then John VI.
With the end of the napoleonic wars, the King returned to Portugal and left his son, Dom Pedro I as regent. This guy went on and proceeded to declare Brazil independent from the crown of Portugal, being styled the Emperor of Brazil. His demand was accepted and there was no war of independence and there was a very short war of independence (less than one year long), in which the Brazilian troops greatly overnumbered the Portuguese forces.
This whole process was VERY different from the way the rest of South America achieved independence, with different colonies succeding in declaring it separetly, and with revolution, replacing monarchy with their own forms of government.
Had the colonies succeeded in their independence wars, before the arrival of the royal family, maybe Brazil would be as divided as the rest of the continent.
Some states have tried to declare independence AFTER Brazil was dettached from Portugal, but these revolts were quickly repressed by the Emperor.
Edit:
Wiki source on the personal union and point information on the independence: https://en.wikipedia.org/wiki/United_Kingdom_of_Portugal,_Brazil_and_the_Algarves
Keep in mind this is not my source, I know this from literature in Portuguese, I figure it would be better if I put something you guys can understand.
Edit²: /u/to-be-determined made an excellent post with sources about what happened, I highly recommend you to read it. Mine is more of a light reading version.
Edit³: I recommend to read the rest of the comments as this is a very short text and there's tons of good, additional information in them, and some other points of view. I'm also fixing some stuff/adding more detail.
Edit4: I don't know every book i've read about Brazilian history, but this topic is covered by the following books (so i consider them to be my sources). They are all in Portuguese.
1808 - from Laurentino Gomes
1822 - from Laurentino Gomes
This website Which dispite its horrible design, it's an official educational website from the Government of Rio de Janeiro, using original documents they still possess.
It should be first noted that Spain and Portugal were "given" their parts of the New World from the Treaty of Tordesillas,^[1] a late 15th century document which drew lines of demarcation between the Portuguese and Spanish (at that time, the Castile) colonies. The Treaty kept disputes to an extreme minimum, in part because the author of the treaty was Pope Alexander VI and the signatories were the Kings and Queens of the two empires in question, three parties you didn't want to piss off regardless of what side you were on. It was also prudent for Spain and Portugal to abide by the treaty, seeing as it ignored all other European powers' (see: those that later became Protestants) claims.
Unlike the Spanish colonies throughout the Americas, which were first ruled by a combination of conquistadors, missionary groups, and then viceroys from the Spanish kingdom in Europe, Portugal's colony was once ruled directly by the Portuguese royal family. When Napoleonic forces invaded Portugal, King João VI and company, with the help of the British, fled to South America.^[2] This turned Portugal's crown colony in the New World to be consolidated and run as the base of operations of its empire for a time. This is the key. Spanish rulers stayed to contend in the Napoleonic Wars and had to rule its New World colonies from thousands of miles away at a time when news and people took months to travel.^[3] As far as the Portuguese were concerned, their home now was the New World, and while they planned on returning to their homeland in the future, they had better do their best to protect and lead what they controlled directly.
The colony was transformed from a subservient part of a kingdom to the national seat of power, a new base of operations. Throughout the Napoleonic Wars and after, international trade continued between the Old World powers and Portuguese-ruled Brazil, bolstering economies on either side of the Atlantic while simultaneously recognizing Brazil's rulers as legitimate. Public works projects were commissioned, magnificent places of worship were constructed, and uprisings were much more easily dealt with.
When it was clear that Napoleon had been beaten and it was safe to return, King João VI left his son, Pedro I, as ruler of Brazil. A little more than a year later, Brazil's independence was championed not by a rag-tag bunch of mestizos and creoles, but by the King's own son, the current ruler of Brazil. No change in leadership occurred, but independence was claimed nonetheless.^[4] Pedro I declared himself the First Emperor of Brazil, and while his father did not immediately recognize his son's claims, he could do little to stop them.
To quote João to Pedro, **"Pedro, Brazil will soon be separated from Portugal: if so, put the crown on your head before some adventurer grabs it."**^[5]
Compare this to the independence of the Spanish colonies. Given their size, Spanish America had been divided into many viceroyalties and regions since its colonization. Rather than one, legitimate voice calling for independence, these colonies had many different factions of varying importance all calling for their own version of freedom. Uprisings from religious factions, indigenous groups, and military strongmen were common throughout the beginning of the 19th century. At the time, Spain could hardly control these warring factions, and had stopped sending Spanish soldiers to the Americas during the Napoleonic wars. In 1820, there was little more than 10,000 Spanish troops throughout the colonies, with half to them being New World-born.^[6] In 1824, that number was greater than 99%.
Unlike in Brazil, the crown wasn’t as relevant or prevalent in Spanish America, so allegiances were dropped, calls for independence were raised, and warring factions resulted in the divisions we see today. These divisions can still be seen on some of the flags of Latin America today (ex. the five stars on the flag of Honduras call for the reuniting of the United States of Central America).^[7]
Treaty between Spain and Portugal concluded at Tordesillas; June 7, 1494
[Cruel War in Spain : Napoleonic Wars] (http://www.napolun.com/mirror/napoleonistyka.atspace.com/cruel_war_in_Spain.html)
Historia do Brasil, Volume 4 by Raphael Maria Galanti
The Americas in the Age of Revolution, 1750-1850 by Lester D. Langley
One reason was that Brazil had been organized as a singular political entity, while Spain organized their South American colonies into four viceroyalties: Rio de Plata, Neuvo Granada, Nuevo Espana, and Peru. This system, along with inherent cultural divides deriving for los indiginos, meant that the the revolutions and the prevailing victors (Bolivar, San Martin, Iturbide) had separate cabals and political and economic interests to appease.
This also created a difference in the length and degree to which the Spanish empire fought. Argentina was the site of British military interventions during the Napoleonic wars, which helped them establish an earlier degree of autonomy. Gran Colombia benefitted from Simon Bolivar, one of the most talented military leaders of the early 19th century (for evidence of this, study The Admirable Campaign). Mexico had the hardest fought and longest of the wars of independence.
So you have disparate start dates and leadership cadres. Adding to this problem, you have secessionism and a strong-executive/weak legislative tradition. This meant that when the strong man (Bolivar, Iturbide) died, there was a storm of competing juntas. Unlike the 13 colonies, the Viceroyalty system did not create any tradition of legislative bodies, only autocratic administrations of patronage and appointment.
Brazil became the seat of the Portuguese government during the Napoleonic wars. This shift, and the reforms of King Pedro II The Magnaminous, advanced and evolved Brazil as a singular unified polity. Thus, the transition from monarchy to republic, the Coup of 1889, was relatively bloodless.
Source: Bushnell, David The Emergence of Latin America in the Nineteenth Century.
I might be a bit late here, but I've wanted to post this question for a while.
How did the Spanish states originally decide upon borders and which countries would exist, what the borders would be (ethnic borders or what)?
Sorry if this is a vague or badly worded question, and I know that there have been border changes through splits (Gran-Colombia) and wars (Pacific?), so current borders aren't the original borders.